{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "notebookstart= time.time()\n",
    "import numpy as np # linear algebra\n",
    "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
    "import os\n",
    "import gc\n",
    "# Models Packages\n",
    "from sklearn import metrics\n",
    "from sklearn.metrics import mean_squared_error\n",
    "from sklearn import feature_selection\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn import preprocessing\n",
    "from sklearn.model_selection import KFold\n",
    "from sklearn import preprocessing\n",
    "from sklearn.metrics import roc_auc_score, roc_curve\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "import category_encoders as ce\n",
    "from imblearn.under_sampling import RandomUnderSampler\n",
    "from catboost import CatBoostClassifier\n",
    "# Gradient Boosting\n",
    "import lightgbm as lgb\n",
    "import xgboost as xgb\n",
    "import category_encoders as ce\n",
    "# Tf-Idf\n",
    "from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer\n",
    "from sklearn.pipeline import FeatureUnion\n",
    "from scipy.sparse import hstack, csr_matrix\n",
    "from nltk.corpus import stopwords \n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn.ensemble import RandomForestRegressor \n",
    "# Viz\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np # linear algebra\n",
    "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
    "from scipy.cluster.vq import kmeans2, whiten\n",
    "from sklearn.neighbors import NearestNeighbors, KNeighborsRegressor\n",
    "from catboost import CatBoostRegressor\n",
    "%matplotlib inline\n",
    "# Input data files are available in the \"../input/\" directory.\n",
    "# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [],
   "source": [
    "num_rows = None\n",
    "EPS = 1e-100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {},
   "outputs": [],
   "source": [
    "train = pd.read_csv('/media/limbo/Home-Credit/data/application_train.csv.zip')\n",
    "y = train['TARGET']\n",
    "\n",
    "n_train = train.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {},
   "outputs": [],
   "source": [
    "descretize = lambda x, n: list(map(str, list(pd.qcut(x, n, duplicates='drop'))))\n",
    "\n",
    "def binary_encoder(df, n_train):\n",
    "    original_columns = list(df.columns)\n",
    "    categorical_columns = [col for col in df.columns if df[col].dtype == 'object']\n",
    "    enc = ce.BinaryEncoder(impute_missing=True, cols=categorical_columns).fit(df[0:n_train], df[0:n_train]['TARGET'])\n",
    "    df = enc.transform(df)\n",
    "    new_columns = [c for c in df.columns if c not in original_columns]\n",
    "    return df[new_columns]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {},
   "outputs": [],
   "source": [
    "def application_train_test(num_rows=num_rows, nan_as_category=False):\n",
    "    # Read data and merge\n",
    "    df = pd.read_csv('../data/application_train.csv.zip', nrows=num_rows)\n",
    "\n",
    "    n_train = df.shape[0]\n",
    "\n",
    "    test_df = pd.read_csv('../data/application_test.csv.zip', nrows=num_rows)\n",
    "    print(\"Train samples: {}, test samples: {}\".format(len(df), len(test_df)))\n",
    "    df = df.append(test_df).reset_index()\n",
    "\n",
    "    df['CODE_GENDER'].replace('XNA', np.nan, inplace=True)\n",
    "    df['DAYS_EMPLOYED'].replace(365243, np.nan, inplace=True)\n",
    "    df['NAME_FAMILY_STATUS'].replace('Unknown', np.nan, inplace=True)\n",
    "    df['ORGANIZATION_TYPE'].replace('XNA', np.nan, inplace=True)\n",
    "\n",
    "    # Optional: Remove 4 applications with XNA CODE_GENDER (train set)\n",
    "    df = df[df['CODE_GENDER'] != 'XNA']\n",
    "\n",
    "    docs = [_f for _f in df.columns if 'FLAG_DOC' in _f]\n",
    "    live = [_f for _f in df.columns if ('FLAG_' in _f) & ('FLAG_DOC' not in _f) & ('_FLAG_' not in _f)]\n",
    "\n",
    "    # NaN values for DAYS_EMPLOYED: 365.243 -> nan\n",
    "    df['DAYS_EMPLOYED'].replace(365243, np.nan, inplace=True)\n",
    "\n",
    "    inc_by_org = df[['AMT_INCOME_TOTAL', 'ORGANIZATION_TYPE']].groupby('ORGANIZATION_TYPE').median()['AMT_INCOME_TOTAL']\n",
    "\n",
    "    df['NEW_CREDIT_TO_ANNUITY_RATIO'] = df['AMT_CREDIT'] / df['AMT_ANNUITY']\n",
    "    df['NEW_AMT_INCOME_TOTAL_RATIO'] = df['AMT_CREDIT'] / df['AMT_INCOME_TOTAL']\n",
    "    df['NEW_CREDIT_TO_GOODS_RATIO'] = df['AMT_CREDIT'] / df['AMT_GOODS_PRICE']\n",
    "    df['NEW_DOC_IND_AVG'] = df[docs].mean(axis=1)\n",
    "    df['NEW_DOC_IND_STD'] = df[docs].std(axis=1)\n",
    "    df['NEW_DOC_IND_KURT'] = df[docs].kurtosis(axis=1)\n",
    "    df['NEW_LIVE_IND_SUM'] = df[live].sum(axis=1)\n",
    "    df['NEW_LIVE_IND_STD'] = df[live].std(axis=1)\n",
    "    df['NEW_LIVE_IND_KURT'] = df[live].kurtosis(axis=1)\n",
    "    df['NEW_INC_PER_CHLD'] = df['AMT_INCOME_TOTAL'] / (1 + df['CNT_CHILDREN'])\n",
    "    df['NEW_INC_BY_ORG'] = df['ORGANIZATION_TYPE'].map(inc_by_org)\n",
    "    df['NEW_EMPLOY_TO_BIRTH_RATIO'] = df['DAYS_EMPLOYED'] / df['DAYS_BIRTH']\n",
    "    df['NEW_ANNUITY_TO_INCOME_RATIO'] = df['AMT_ANNUITY'] / (1 + df['AMT_INCOME_TOTAL'])\n",
    "    df['NEW_SOURCES_PROD'] = df['EXT_SOURCE_1'] * df['EXT_SOURCE_2'] * df['EXT_SOURCE_3']\n",
    "    df['NEW_EXT_SOURCES_MEAN'] = df[['EXT_SOURCE_1', 'EXT_SOURCE_2', 'EXT_SOURCE_3']].mean(axis=1)\n",
    "    df['NEW_SCORES_STD'] = df[['EXT_SOURCE_1', 'EXT_SOURCE_2', 'EXT_SOURCE_3']].std(axis=1)\n",
    "    df['NEW_SCORES_STD'] = df['NEW_SCORES_STD'].fillna(df['NEW_SCORES_STD'].mean())\n",
    "    df['NEW_CAR_TO_BIRTH_RATIO'] = df['OWN_CAR_AGE'] / df['DAYS_BIRTH']\n",
    "    df['NEW_CAR_TO_EMPLOY_RATIO'] = df['OWN_CAR_AGE'] / df['DAYS_EMPLOYED']\n",
    "    df['NEW_PHONE_TO_BIRTH_RATIO'] = df['DAYS_LAST_PHONE_CHANGE'] / df['DAYS_BIRTH']\n",
    "    df['NEW_PHONE_TO_EMPLOY_RATIO'] = df['DAYS_LAST_PHONE_CHANGE'] / df['DAYS_EMPLOYED']\n",
    "    df['NEW_CREDIT_TO_INCOME_RATIO'] = df['AMT_CREDIT'] / df['AMT_INCOME_TOTAL']\n",
    "\n",
    "#     df['children_ratio'] = df['CNT_CHILDREN'] / df['CNT_FAM_MEMBERS']\n",
    "\n",
    "#     df['NEW_EXT_SOURCES_MEDIAN'] = df[['EXT_SOURCE_1', 'EXT_SOURCE_2', 'EXT_SOURCE_3']].median(axis=1)\n",
    "\n",
    "#     df['NEW_DOC_IND_SKEW'] = df[docs].skew(axis=1)\n",
    "#     df['NEW_LIVE_IND_SKEW'] = df[live].skew(axis=1)\n",
    "\n",
    "#     df['ind_0'] = df['DAYS_EMPLOYED'] - df['DAYS_EMPLOYED'].replace([np.inf, -np.inf], np.nan).fillna(\n",
    "#         df['DAYS_EMPLOYED'].dropna().median()).mean()\n",
    "#     df['ind_1'] = df['DAYS_EMPLOYED'] - df['DAYS_EMPLOYED'].replace([np.inf, -np.inf], np.nan).fillna(\n",
    "#         df['DAYS_EMPLOYED'].dropna().median()).median()\n",
    "\n",
    "#     df['ind_2'] = df['DAYS_BIRTH'] - df['DAYS_BIRTH'].replace([np.inf, -np.inf], np.nan).fillna(\n",
    "#         df['DAYS_BIRTH'].dropna().median()).mean()\n",
    "#     df['ind_3'] = df['DAYS_BIRTH'] - df['DAYS_BIRTH'].replace([np.inf, -np.inf], np.nan).fillna(\n",
    "#         df['DAYS_BIRTH'].dropna().median()).median()\n",
    "\n",
    "#     df['ind_4'] = df['AMT_INCOME_TOTAL'] - df['AMT_INCOME_TOTAL'].replace([np.inf, -np.inf], np.nan).fillna(\n",
    "#         df['AMT_INCOME_TOTAL'].dropna().median()).mean()\n",
    "#     df['ind_5'] = df['AMT_INCOME_TOTAL'] - df['AMT_INCOME_TOTAL'].replace([np.inf, -np.inf], np.nan).fillna(\n",
    "#         df['AMT_INCOME_TOTAL'].dropna().median()).median()\n",
    "\n",
    "#     df['ind_6'] = df['AMT_CREDIT'] - df['AMT_CREDIT'].replace([np.inf, -np.inf], np.nan).fillna(\n",
    "#         df['AMT_CREDIT'].dropna().median()).mean()\n",
    "#     df['ind_7'] = df['AMT_CREDIT'] - df['AMT_CREDIT'].replace([np.inf, -np.inf], np.nan).fillna(\n",
    "#         df['AMT_CREDIT'].dropna().median()).median()\n",
    "\n",
    "#     df['ind_8'] = df['AMT_ANNUITY'] - df['AMT_ANNUITY'].replace([np.inf, -np.inf], np.nan).fillna(\n",
    "#         df['AMT_ANNUITY'].dropna().median()).mean()\n",
    "#     df['ind_9'] = df['AMT_ANNUITY'] - df['AMT_ANNUITY'].replace([np.inf, -np.inf], np.nan).fillna(\n",
    "#         df['AMT_ANNUITY'].dropna().median()).median()\n",
    "\n",
    "#     df['ind_10'] = df['AMT_CREDIT'] - df['AMT_INCOME_TOTAL'].replace([np.inf, -np.inf], np.nan).fillna(\n",
    "#         df['AMT_INCOME_TOTAL'].dropna().median()).mean()\n",
    "#     df['ind_11'] = df['AMT_CREDIT'] - df['AMT_INCOME_TOTAL'].replace([np.inf, -np.inf], np.nan).fillna(\n",
    "#         df['AMT_INCOME_TOTAL'].dropna().median()).median()\n",
    "\n",
    "#     AGGREGATION_RECIPIES = [\n",
    "#         (['CODE_GENDER', 'NAME_EDUCATION_TYPE'], [('AMT_ANNUITY', 'max'),\n",
    "#                                                   ('AMT_CREDIT', 'max'),\n",
    "#                                                   ('EXT_SOURCE_1', 'mean'),\n",
    "#                                                   ('EXT_SOURCE_2', 'mean'),\n",
    "#                                                   ('OWN_CAR_AGE', 'max'),\n",
    "#                                                   ('OWN_CAR_AGE', 'sum')]),\n",
    "#         (['CODE_GENDER', 'ORGANIZATION_TYPE'], [('AMT_ANNUITY', 'mean'),\n",
    "#                                                 ('AMT_INCOME_TOTAL', 'mean'),\n",
    "#                                                 ('DAYS_REGISTRATION', 'mean'),\n",
    "#                                                 ('EXT_SOURCE_1', 'mean'),\n",
    "#                                                 ('NEW_CREDIT_TO_ANNUITY_RATIO', 'mean')]),\n",
    "#         (['CODE_GENDER', 'REG_CITY_NOT_WORK_CITY'], [('AMT_ANNUITY', 'mean'),\n",
    "#                                                      ('CNT_CHILDREN', 'mean'),\n",
    "#                                                      ('DAYS_ID_PUBLISH', 'mean')]),\n",
    "#         (['CODE_GENDER', 'NAME_EDUCATION_TYPE', 'OCCUPATION_TYPE', 'REG_CITY_NOT_WORK_CITY'], [('EXT_SOURCE_1', 'mean'),\n",
    "#                                                                                                ('EXT_SOURCE_2',\n",
    "#                                                                                                 'mean')]),\n",
    "#         (['NAME_EDUCATION_TYPE', 'OCCUPATION_TYPE'], [('AMT_CREDIT', 'mean'),\n",
    "#                                                       ('AMT_REQ_CREDIT_BUREAU_YEAR', 'mean'),\n",
    "#                                                       ('APARTMENTS_AVG', 'mean'),\n",
    "#                                                       ('BASEMENTAREA_AVG', 'mean'),\n",
    "#                                                       ('EXT_SOURCE_1', 'mean'),\n",
    "#                                                       ('EXT_SOURCE_2', 'mean'),\n",
    "#                                                       ('EXT_SOURCE_3', 'mean'),\n",
    "#                                                       ('NONLIVINGAREA_AVG', 'mean'),\n",
    "#                                                       ('OWN_CAR_AGE', 'mean')]),\n",
    "#         (['NAME_EDUCATION_TYPE', 'OCCUPATION_TYPE', 'REG_CITY_NOT_WORK_CITY'], [('ELEVATORS_AVG', 'mean'),\n",
    "#                                                                                 ('EXT_SOURCE_1', 'mean')]),\n",
    "#         (['OCCUPATION_TYPE'], [('AMT_ANNUITY', 'mean'),\n",
    "#                                ('CNT_CHILDREN', 'mean'),\n",
    "#                                ('CNT_FAM_MEMBERS',  'mean'),\n",
    "#                                ('DAYS_BIRTH', 'mean'),\n",
    "#                                ('DAYS_EMPLOYED',  'mean'),\n",
    "#                                ('NEW_CREDIT_TO_ANNUITY_RATIO', 'median'),\n",
    "#                                ('DAYS_REGISTRATION', 'mean'),\n",
    "#                                ('EXT_SOURCE_1', 'mean'),\n",
    "#                                ('EXT_SOURCE_2', 'mean'),\n",
    "#                                ('EXT_SOURCE_3',  'mean')]),\n",
    "#     ]\n",
    "\n",
    "#     for groupby_cols, specs in AGGREGATION_RECIPIES:\n",
    "#         group_object = df.groupby(groupby_cols)\n",
    "#         for select, agg in specs:\n",
    "#             groupby_aggregate_name = '{}_{}_{}'.format('_'.join(groupby_cols), agg, select)\n",
    "#             df = df.merge(group_object[select]\n",
    "#                           .agg(agg)\n",
    "#                           .reset_index()\n",
    "#                           .rename(index=str,\n",
    "#                                   columns={select: groupby_aggregate_name})\n",
    "#                           [groupby_cols + [groupby_aggregate_name]],\n",
    "#                           on=groupby_cols,\n",
    "#                           how='left')\n",
    "    # ['DAYS_EMPLOYED', 'CNT_FAM_MEMBERS', 'CNT_CHILDREN', 'credit_per_person', 'cnt_non_child']\n",
    "    df['retirement_age'] = (df['DAYS_BIRTH'] > -14000).astype(int)\n",
    "    df['long_employment'] = (df['DAYS_EMPLOYED'] > -2000).astype(int)\n",
    "    df['cnt_non_child'] = df['CNT_FAM_MEMBERS'] - df['CNT_CHILDREN']\n",
    "    df['child_to_non_child_ratio'] = df['CNT_CHILDREN'] / df['cnt_non_child']\n",
    "    df['income_per_non_child'] = df['AMT_INCOME_TOTAL'] / df['cnt_non_child']\n",
    "    df['credit_per_person'] = df['AMT_CREDIT'] / df['CNT_FAM_MEMBERS']\n",
    "    df['credit_per_child'] = df['AMT_CREDIT'] / (1 + df['CNT_CHILDREN'])\n",
    "    df['credit_per_non_child'] = df['AMT_CREDIT'] / df['cnt_non_child']\n",
    "\n",
    "    df['cnt_non_child'] = df['CNT_FAM_MEMBERS'] - df['CNT_CHILDREN']\n",
    "    df['child_to_non_child_ratio'] = df['CNT_CHILDREN'] / df['cnt_non_child']\n",
    "    df['income_per_non_child'] = df['AMT_INCOME_TOTAL'] / df['cnt_non_child']\n",
    "    df['credit_per_person'] = df['AMT_CREDIT'] / df['CNT_FAM_MEMBERS']\n",
    "    df['credit_per_child'] = df['AMT_CREDIT'] / (1 + df['CNT_CHILDREN'])\n",
    "    df['credit_per_non_child'] = df['AMT_CREDIT'] / df['cnt_non_child']\n",
    "\n",
    "#     df['p_0'] = descretize(df['credit_per_non_child'].values, 2 ** 5)\n",
    "#     df['p_1'] = descretize(df['credit_per_person'].values, 2 ** 5)\n",
    "#     df['p_2'] = descretize(df['credit_per_child'].values, 2 ** 5)\n",
    "#     df['p_3'] = descretize(df['retirement_age'].values, 2 ** 5)\n",
    "#     df['p_4'] = descretize(df['income_per_non_child'].values, 2 ** 5)\n",
    "#     df['p_5'] = descretize(df['child_to_non_child_ratio'].values, 2 ** 5)\n",
    "\n",
    "#     df['p_6'] = descretize(df['NEW_CREDIT_TO_ANNUITY_RATIO'].values, 2 ** 5)\n",
    "#     df['p_7'] = descretize(df['NEW_CREDIT_TO_ANNUITY_RATIO'].values, 2 ** 6)\n",
    "#     df['p_8'] = descretize(df['NEW_CREDIT_TO_ANNUITY_RATIO'].values, 2 ** 7)\n",
    "\n",
    "#     df['pe_0'] = descretize(df['credit_per_non_child'].values, 2 ** 6)\n",
    "#     df['pe_1'] = descretize(df['credit_per_person'].values, 2 ** 6)\n",
    "#     df['pe_2'] = descretize(df['credit_per_child'].values, 2 ** 6)\n",
    "#     df['pe_3'] = descretize(df['retirement_age'].values, 2 ** 6)\n",
    "#     df['pe_4'] = descretize(df['income_per_non_child'].values, 2 ** 6)\n",
    "#     df['pe_5'] = descretize(df['child_to_non_child_ratio'].values, 2 ** 6)\n",
    "\n",
    "    c = df['NEW_CREDIT_TO_ANNUITY_RATIO'].replace([np.inf, -np.inf], np.nan).fillna(999).values\n",
    "    a, b = kmeans2(np.log1p(c), 2, iter=333)\n",
    "    df['x_0'] = b\n",
    "\n",
    "    a, b = kmeans2(np.log1p(c), 4, iter=333)\n",
    "    df['x_1'] = b\n",
    "\n",
    "    a, b = kmeans2(np.log1p(c), 8, iter=333)\n",
    "    df['x_2'] = b\n",
    "\n",
    "    a, b = kmeans2(np.log1p(c), 16, iter=333)\n",
    "    df['x_3'] = b\n",
    "\n",
    "    a, b = kmeans2(np.log1p(c), 32, iter=333)\n",
    "    df['x_4'] = b\n",
    "\n",
    "    a, b = kmeans2(np.log1p(c), 64, iter=333)\n",
    "    df['x_5'] = b\n",
    "\n",
    "    a, b = kmeans2(np.log1p(c), 128, iter=333)\n",
    "    df['x_6'] = b\n",
    "\n",
    "    a, b = kmeans2(np.log1p(c), 150, iter=333)\n",
    "    df['x_7'] = b\n",
    "\n",
    "    a, b = kmeans2(np.log1p(c), 256, iter=333)\n",
    "    df['x_8'] = b\n",
    "\n",
    "    a, b = kmeans2(np.log1p(c), 512, iter=333)\n",
    "    df['x_9'] = b\n",
    "\n",
    "    a, b = kmeans2(np.log1p(c), 1024, iter=333)\n",
    "    df['x_10'] = b\n",
    "    \n",
    "    \n",
    "#     c = df['EXT_SOURCE_1'].replace([np.inf, -np.inf], np.nan).fillna(999).values\n",
    "#     a, b = kmeans2(np.log1p(c), 2, iter=333)\n",
    "#     df['ex1_0'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 4, iter=333)\n",
    "#     df['ex1_1'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 8, iter=333)\n",
    "#     df['ex1_2'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 16, iter=333)\n",
    "#     df['ex1_3'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 32, iter=333)\n",
    "#     df['ex1_4'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 64, iter=333)\n",
    "#     df['ex1_5'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 128, iter=333)\n",
    "#     df['ex1_6'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 256, iter=333)\n",
    "#     df['ex1_7'] = b    \n",
    "    \n",
    "    \n",
    "#     c = df['EXT_SOURCE_2'].replace([np.inf, -np.inf], np.nan).fillna(999).values\n",
    "#     a, b = kmeans2(np.log1p(c), 2, iter=333)\n",
    "#     df['ex2_0'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 4, iter=333)\n",
    "#     df['ex2_1'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 8, iter=333)\n",
    "#     df['ex2_2'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 16, iter=333)\n",
    "#     df['ex2_3'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 32, iter=333)\n",
    "#     df['ex2_4'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 64, iter=333)\n",
    "#     df['ex2_5'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 128, iter=333)\n",
    "#     df['ex2_6'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 256, iter=333)\n",
    "#     df['ex2_7'] = b \n",
    "    \n",
    "#     c = df['EXT_SOURCE_3'].replace([np.inf, -np.inf], np.nan).fillna(999).values\n",
    "#     a, b = kmeans2(np.log1p(c), 2, iter=333)\n",
    "#     df['ex3_0'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 4, iter=333)\n",
    "#     df['ex3_1'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 8, iter=333)\n",
    "#     df['ex3_2'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 16, iter=333)\n",
    "#     df['ex3_3'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 32, iter=333)\n",
    "#     df['ex3_4'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 64, iter=333)\n",
    "#     df['ex3_5'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 128, iter=333)\n",
    "#     df['ex3_6'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 256, iter=333)\n",
    "#     df['ex3_7'] = b \n",
    "    \n",
    "\n",
    "#     df['ex_1_0'] = descretize(df['EXT_SOURCE_1'].values, 2 ** 6)\n",
    "#     df['ex_2_0'] = descretize(df['EXT_SOURCE_2'].values, 2 ** 6)\n",
    "#     df['ex_3_0'] = descretize(df['EXT_SOURCE_3'].values, 2 ** 6)\n",
    "\n",
    "#     df['ex_1_1'] = descretize(df['EXT_SOURCE_1'].values, 2 ** 4)\n",
    "#     df['ex_2_1'] = descretize(df['EXT_SOURCE_2'].values, 2 ** 4)\n",
    "#     df['ex_3_1'] = descretize(df['EXT_SOURCE_3'].values, 2 ** 4)\n",
    "\n",
    "#     df['ex_1_2'] = descretize(df['EXT_SOURCE_1'].values, 2 ** 5)\n",
    "#     df['ex_2_2'] = descretize(df['EXT_SOURCE_2'].values, 2 ** 5)\n",
    "#     df['ex_3_2'] = descretize(df['EXT_SOURCE_3'].values, 2 ** 5)\n",
    "\n",
    "#     df['ex_1_3'] = descretize(df['EXT_SOURCE_1'].values, 2 ** 3)\n",
    "#     df['ex_2_4'] = descretize(df['EXT_SOURCE_2'].values, 2 ** 3)\n",
    "#     df['ex_3_5'] = descretize(df['EXT_SOURCE_3'].values, 2 ** 3)\n",
    "\n",
    "#     c = df['NEW_EXT_SOURCES_MEAN'].replace([np.inf, -np.inf], np.nan).fillna(999).values\n",
    "#     a, b = kmeans2(np.log1p(c), 2, iter=333)\n",
    "#     df['ex_mean_0'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 4, iter=333)\n",
    "#     df['ex_mean_1'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 8, iter=333)\n",
    "#     df['ex_mean_2'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 16, iter=333)\n",
    "#     df['ex_mean_3'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 32, iter=333)\n",
    "#     df['ex_mean_4'] = b\n",
    "\n",
    "#     a, b = kmeans2(np.log1p(c), 64, iter=333)\n",
    "#     df['ex_mean_5'] = b\n",
    "    \n",
    "    \n",
    "    \n",
    "\n",
    "\n",
    "#     df['NEW_SCORES_STD'] = df[['EXT_SOURCE_1', 'EXT_SOURCE_2', 'EXT_SOURCE_3']].std(axis=1)\n",
    "    \n",
    "#     df['ex1/ex2'] = df['EXT_SOURCE_1'] / df['EXT_SOURCE_2']\n",
    "#     df['ex1/ex3'] = df['EXT_SOURCE_1'] / df['EXT_SOURCE_3']\n",
    "#     df['ex2/ex3'] = df['EXT_SOURCE_3'] / df['EXT_SOURCE_3']\n",
    "    \n",
    "#     df['ex1*ex2'] = df['EXT_SOURCE_1'] * df['EXT_SOURCE_2']\n",
    "#     df['ex1*ex3'] = df['EXT_SOURCE_1'] * df['EXT_SOURCE_3']\n",
    "#     df['ex2*ex3'] = df['EXT_SOURCE_2'] * df['EXT_SOURCE_3']\n",
    "    \n",
    "#     df['cred*ex1'] = df['AMT_CREDIT'] * df['EXT_SOURCE_1']\n",
    "#     df['cred*ex2'] = df['AMT_CREDIT'] * df['EXT_SOURCE_2']\n",
    "#     df['cred*ex3'] = df['AMT_CREDIT'] * df['EXT_SOURCE_3']\n",
    "    \n",
    "#     df['cred/ex1'] = df['AMT_CREDIT'] / df['EXT_SOURCE_1']\n",
    "#     df['cred/ex2'] = df['AMT_CREDIT'] / df['EXT_SOURCE_2']\n",
    "#     df['cred/ex3'] = df['AMT_CREDIT'] / df['EXT_SOURCE_3']\n",
    "    \n",
    "#     df['cred*ex123'] = df['AMT_CREDIT'] * df['EXT_SOURCE_1'] * df['EXT_SOURCE_2'] * df['EXT_SOURCE_3']\n",
    "    \n",
    "#     del df['EXT_SOURCE_1']\n",
    "#     del df['EXT_SOURCE_2']\n",
    "#     del df['EXT_SOURCE_3']\n",
    "#     del df['NEW_EXT_SOURCES_MEAN']\n",
    "\n",
    "    # Categorical features with Binary encode (0 or 1; two categories)\n",
    "    for bin_feature in ['CODE_GENDER', 'FLAG_OWN_CAR', 'FLAG_OWN_REALTY']:\n",
    "        df[bin_feature], uniques = pd.factorize(df[bin_feature])\n",
    "    \n",
    "    del test_df\n",
    "    gc.collect()\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train samples: 307511, test samples: 48744\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/kain/Workstation/PyEnv/lib/python3.5/site-packages/pandas/core/frame.py:6211: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version\n",
      "of pandas will change to not sort by default.\n",
      "\n",
      "To accept the future behavior, pass 'sort=False'.\n",
      "\n",
      "To retain the current behavior and silence the warning, pass 'sort=True'.\n",
      "\n",
      "  sort=sort)\n",
      "/home/kain/Workstation/PyEnv/lib/python3.5/site-packages/scipy/cluster/vq.py:523: UserWarning: One of the clusters is empty. Re-run kmeans with a different initialization.\n",
      "  warnings.warn(\"One of the clusters is empty. \"\n"
     ]
    }
   ],
   "source": [
    "df = application_train_test(num_rows=num_rows, nan_as_category=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>AMT_ANNUITY</th>\n",
       "      <th>AMT_CREDIT</th>\n",
       "      <th>AMT_GOODS_PRICE</th>\n",
       "      <th>AMT_INCOME_TOTAL</th>\n",
       "      <th>AMT_REQ_CREDIT_BUREAU_DAY</th>\n",
       "      <th>AMT_REQ_CREDIT_BUREAU_HOUR</th>\n",
       "      <th>AMT_REQ_CREDIT_BUREAU_MON</th>\n",
       "      <th>AMT_REQ_CREDIT_BUREAU_QRT</th>\n",
       "      <th>AMT_REQ_CREDIT_BUREAU_WEEK</th>\n",
       "      <th>...</th>\n",
       "      <th>x_1</th>\n",
       "      <th>x_2</th>\n",
       "      <th>x_3</th>\n",
       "      <th>x_4</th>\n",
       "      <th>x_5</th>\n",
       "      <th>x_6</th>\n",
       "      <th>x_7</th>\n",
       "      <th>x_8</th>\n",
       "      <th>x_9</th>\n",
       "      <th>x_10</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>24700.5</td>\n",
       "      <td>406597.5</td>\n",
       "      <td>351000.0</td>\n",
       "      <td>202500.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>12</td>\n",
       "      <td>3</td>\n",
       "      <td>31</td>\n",
       "      <td>8</td>\n",
       "      <td>42</td>\n",
       "      <td>157</td>\n",
       "      <td>277</td>\n",
       "      <td>106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>35698.5</td>\n",
       "      <td>1293502.5</td>\n",
       "      <td>1129500.0</td>\n",
       "      <td>270000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>22</td>\n",
       "      <td>42</td>\n",
       "      <td>68</td>\n",
       "      <td>81</td>\n",
       "      <td>112</td>\n",
       "      <td>98</td>\n",
       "      <td>531</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>6750.0</td>\n",
       "      <td>135000.0</td>\n",
       "      <td>135000.0</td>\n",
       "      <td>67500.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>7</td>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>56</td>\n",
       "      <td>73</td>\n",
       "      <td>207</td>\n",
       "      <td>120</td>\n",
       "      <td>289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>29686.5</td>\n",
       "      <td>312682.5</td>\n",
       "      <td>297000.0</td>\n",
       "      <td>135000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>9</td>\n",
       "      <td>20</td>\n",
       "      <td>10</td>\n",
       "      <td>7</td>\n",
       "      <td>25</td>\n",
       "      <td>217</td>\n",
       "      <td>351</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>21865.5</td>\n",
       "      <td>513000.0</td>\n",
       "      <td>513000.0</td>\n",
       "      <td>121500.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "      <td>10</td>\n",
       "      <td>60</td>\n",
       "      <td>16</td>\n",
       "      <td>141</td>\n",
       "      <td>172</td>\n",
       "      <td>264</td>\n",
       "      <td>147</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 163 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   index  AMT_ANNUITY  AMT_CREDIT  AMT_GOODS_PRICE  AMT_INCOME_TOTAL  \\\n",
       "0      0      24700.5    406597.5         351000.0          202500.0   \n",
       "1      1      35698.5   1293502.5        1129500.0          270000.0   \n",
       "2      2       6750.0    135000.0         135000.0           67500.0   \n",
       "3      3      29686.5    312682.5         297000.0          135000.0   \n",
       "4      4      21865.5    513000.0         513000.0          121500.0   \n",
       "\n",
       "   AMT_REQ_CREDIT_BUREAU_DAY  AMT_REQ_CREDIT_BUREAU_HOUR  \\\n",
       "0                        0.0                         0.0   \n",
       "1                        0.0                         0.0   \n",
       "2                        0.0                         0.0   \n",
       "3                        NaN                         NaN   \n",
       "4                        0.0                         0.0   \n",
       "\n",
       "   AMT_REQ_CREDIT_BUREAU_MON  AMT_REQ_CREDIT_BUREAU_QRT  \\\n",
       "0                        0.0                        0.0   \n",
       "1                        0.0                        0.0   \n",
       "2                        0.0                        0.0   \n",
       "3                        NaN                        NaN   \n",
       "4                        0.0                        0.0   \n",
       "\n",
       "   AMT_REQ_CREDIT_BUREAU_WEEK  ...   x_1  x_2  x_3  x_4  x_5  x_6  x_7  x_8  \\\n",
       "0                         0.0  ...     2    5   12    3   31    8   42  157   \n",
       "1                         0.0  ...     3    6    8   22   42   68   81  112   \n",
       "2                         0.0  ...     2    4    7   15    2   56   73  207   \n",
       "3                         NaN  ...     0    7    9   20   10    7   25  217   \n",
       "4                         0.0  ...     1    2    6   10   60   16  141  172   \n",
       "\n",
       "   x_9  x_10  \n",
       "0  277   106  \n",
       "1   98   531  \n",
       "2  120   289  \n",
       "3  351    74  \n",
       "4  264   147  \n",
       "\n",
       "[5 rows x 163 columns]"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "metadata": {},
   "outputs": [],
   "source": [
    "selected_features = ['AMT_ANNUITY', 'AMT_CREDIT', 'AMT_INCOME_TOTAL', 'NEW_CREDIT_TO_ANNUITY_RATIO', 'NEW_CREDIT_TO_GOODS_RATIO', 'NEW_CREDIT_TO_INCOME_RATIO']  + ['x_' + str(x) for x in range(11)] + \\\n",
    "['retirement_age', 'long_employment'] + ['EXT_SOURCE_1', 'EXT_SOURCE_2', 'EXT_SOURCE_3']\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {},
   "outputs": [],
   "source": [
    "categorical_columns = [col for col in train.columns if train[col].dtype == 'object']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [],
   "source": [
    "numerical_columns = [col for col in df.columns if df[col].dtype != 'object']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_df = df.copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = new_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {},
   "outputs": [],
   "source": [
    "encoder = preprocessing.LabelEncoder()\n",
    "\n",
    "for f in categorical_columns:\n",
    "    if df[f].dtype == 'object':\n",
    "        df[f] = encoder.fit_transform(df[f].apply(str).values) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['NAME_CONTRACT_TYPE',\n",
       " 'CODE_GENDER',\n",
       " 'FLAG_OWN_CAR',\n",
       " 'FLAG_OWN_REALTY',\n",
       " 'NAME_TYPE_SUITE',\n",
       " 'NAME_INCOME_TYPE',\n",
       " 'NAME_EDUCATION_TYPE',\n",
       " 'NAME_FAMILY_STATUS',\n",
       " 'NAME_HOUSING_TYPE',\n",
       " 'OCCUPATION_TYPE',\n",
       " 'WEEKDAY_APPR_PROCESS_START',\n",
       " 'ORGANIZATION_TYPE',\n",
       " 'FONDKAPREMONT_MODE',\n",
       " 'HOUSETYPE_MODE',\n",
       " 'WALLSMATERIAL_MODE',\n",
       " 'EMERGENCYSTATE_MODE']"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "categorical_columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21"
      ]
     },
     "execution_count": 153,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gc.collect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/kain/Workstation/PyEnv/lib/python3.5/site-packages/ipykernel_launcher.py:5: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version\n",
      "of pandas will change to not sort by default.\n",
      "\n",
      "To accept the future behavior, pass 'sort=False'.\n",
      "\n",
      "To retain the current behavior and silence the warning, pass 'sort=True'.\n",
      "\n",
      "  \"\"\"\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "28"
      ]
     },
     "execution_count": 154,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train = pd.read_csv('../data/application_train.csv.zip', nrows=num_rows)\n",
    "n_train = train.shape[0]\n",
    "test = pd.read_csv('../data/application_test.csv.zip', nrows=num_rows)\n",
    "    \n",
    "new_df = pd.concat([train, test], axis=0)\n",
    "gc.collect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(356255, 122)"
      ]
     },
     "execution_count": 155,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>NAME_CONTRACT_TYPE</th>\n",
       "      <th>CODE_GENDER</th>\n",
       "      <th>FLAG_OWN_CAR</th>\n",
       "      <th>FLAG_OWN_REALTY</th>\n",
       "      <th>NAME_TYPE_SUITE</th>\n",
       "      <th>NAME_INCOME_TYPE</th>\n",
       "      <th>NAME_EDUCATION_TYPE</th>\n",
       "      <th>NAME_FAMILY_STATUS</th>\n",
       "      <th>NAME_HOUSING_TYPE</th>\n",
       "      <th>OCCUPATION_TYPE</th>\n",
       "      <th>WEEKDAY_APPR_PROCESS_START</th>\n",
       "      <th>ORGANIZATION_TYPE</th>\n",
       "      <th>FONDKAPREMONT_MODE</th>\n",
       "      <th>HOUSETYPE_MODE</th>\n",
       "      <th>WALLSMATERIAL_MODE</th>\n",
       "      <th>EMERGENCYSTATE_MODE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Cash loans</td>\n",
       "      <td>M</td>\n",
       "      <td>N</td>\n",
       "      <td>Y</td>\n",
       "      <td>Unaccompanied</td>\n",
       "      <td>Working</td>\n",
       "      <td>Secondary / secondary special</td>\n",
       "      <td>Single / not married</td>\n",
       "      <td>House / apartment</td>\n",
       "      <td>Laborers</td>\n",
       "      <td>WEDNESDAY</td>\n",
       "      <td>Business Entity Type 3</td>\n",
       "      <td>reg oper account</td>\n",
       "      <td>block of flats</td>\n",
       "      <td>Stone, brick</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Cash loans</td>\n",
       "      <td>F</td>\n",
       "      <td>N</td>\n",
       "      <td>N</td>\n",
       "      <td>Family</td>\n",
       "      <td>State servant</td>\n",
       "      <td>Higher education</td>\n",
       "      <td>Married</td>\n",
       "      <td>House / apartment</td>\n",
       "      <td>Core staff</td>\n",
       "      <td>MONDAY</td>\n",
       "      <td>School</td>\n",
       "      <td>reg oper account</td>\n",
       "      <td>block of flats</td>\n",
       "      <td>Block</td>\n",
       "      <td>No</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Revolving loans</td>\n",
       "      <td>M</td>\n",
       "      <td>Y</td>\n",
       "      <td>Y</td>\n",
       "      <td>Unaccompanied</td>\n",
       "      <td>Working</td>\n",
       "      <td>Secondary / secondary special</td>\n",
       "      <td>Single / not married</td>\n",
       "      <td>House / apartment</td>\n",
       "      <td>Laborers</td>\n",
       "      <td>MONDAY</td>\n",
       "      <td>Government</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Cash loans</td>\n",
       "      <td>F</td>\n",
       "      <td>N</td>\n",
       "      <td>Y</td>\n",
       "      <td>Unaccompanied</td>\n",
       "      <td>Working</td>\n",
       "      <td>Secondary / secondary special</td>\n",
       "      <td>Civil marriage</td>\n",
       "      <td>House / apartment</td>\n",
       "      <td>Laborers</td>\n",
       "      <td>WEDNESDAY</td>\n",
       "      <td>Business Entity Type 3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Cash loans</td>\n",
       "      <td>M</td>\n",
       "      <td>N</td>\n",
       "      <td>Y</td>\n",
       "      <td>Unaccompanied</td>\n",
       "      <td>Working</td>\n",
       "      <td>Secondary / secondary special</td>\n",
       "      <td>Single / not married</td>\n",
       "      <td>House / apartment</td>\n",
       "      <td>Core staff</td>\n",
       "      <td>THURSDAY</td>\n",
       "      <td>Religion</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  NAME_CONTRACT_TYPE CODE_GENDER FLAG_OWN_CAR FLAG_OWN_REALTY NAME_TYPE_SUITE  \\\n",
       "0         Cash loans           M            N               Y   Unaccompanied   \n",
       "1         Cash loans           F            N               N          Family   \n",
       "2    Revolving loans           M            Y               Y   Unaccompanied   \n",
       "3         Cash loans           F            N               Y   Unaccompanied   \n",
       "4         Cash loans           M            N               Y   Unaccompanied   \n",
       "\n",
       "  NAME_INCOME_TYPE            NAME_EDUCATION_TYPE    NAME_FAMILY_STATUS  \\\n",
       "0          Working  Secondary / secondary special  Single / not married   \n",
       "1    State servant               Higher education               Married   \n",
       "2          Working  Secondary / secondary special  Single / not married   \n",
       "3          Working  Secondary / secondary special        Civil marriage   \n",
       "4          Working  Secondary / secondary special  Single / not married   \n",
       "\n",
       "   NAME_HOUSING_TYPE OCCUPATION_TYPE WEEKDAY_APPR_PROCESS_START  \\\n",
       "0  House / apartment        Laborers                  WEDNESDAY   \n",
       "1  House / apartment      Core staff                     MONDAY   \n",
       "2  House / apartment        Laborers                     MONDAY   \n",
       "3  House / apartment        Laborers                  WEDNESDAY   \n",
       "4  House / apartment      Core staff                   THURSDAY   \n",
       "\n",
       "        ORGANIZATION_TYPE FONDKAPREMONT_MODE  HOUSETYPE_MODE  \\\n",
       "0  Business Entity Type 3   reg oper account  block of flats   \n",
       "1                  School   reg oper account  block of flats   \n",
       "2              Government                NaN             NaN   \n",
       "3  Business Entity Type 3                NaN             NaN   \n",
       "4                Religion                NaN             NaN   \n",
       "\n",
       "  WALLSMATERIAL_MODE EMERGENCYSTATE_MODE  \n",
       "0       Stone, brick                  No  \n",
       "1              Block                  No  \n",
       "2                NaN                 NaN  \n",
       "3                NaN                 NaN  \n",
       "4                NaN                 NaN  "
      ]
     },
     "execution_count": 156,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_df[categorical_columns].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [],
   "source": [
    "encoder = preprocessing.LabelEncoder()\n",
    "\n",
    "for f in categorical_columns:\n",
    "    if new_df[f].dtype == 'object':\n",
    "        new_df[f] = encoder.fit_transform(new_df[f].apply(str).values) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_features = pd.read_csv('selected_features.csv', header=0, index_col=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EXT_1_DIV_BIRTH_SURESH</th>\n",
       "      <th>EXT_3_DIV_BIRTH_SURESH</th>\n",
       "      <th>EXT_2_DIV_BIRTH_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_LATE_LAST_LOAN_MEAN_SURESH</th>\n",
       "      <th>AMT_CREDIT_DIFF_AMT_GOODS_SURESH</th>\n",
       "      <th>BUREAU_DEBT_CREDIT_RATIO_SURESH</th>\n",
       "      <th>PREVIOUS_APPLICATION_FRACTION_OF_REFUSED_APPLICATIONS_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_MAX_SURESH</th>\n",
       "      <th>TREND_INTER_FUTURE_CNT_SURESH</th>\n",
       "      <th>TREND_COEF_DPD_DEF_SURESH</th>\n",
       "      <th>...</th>\n",
       "      <th>INSTALLMENT_PAID_LATE_IN_DAYS_12_MONTHS_MAX_SURESH</th>\n",
       "      <th>BUREAU_CREDIT_ACTIVE_BINARY_MEAN_SURESH</th>\n",
       "      <th>DEF_30_60_SOCIAL_SUM_SURESH</th>\n",
       "      <th>POPULAR_AMT_GOODS_PRICE_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_MEAN_SURESH</th>\n",
       "      <th>MEAN_PAYMENT_CC_SURESH</th>\n",
       "      <th>DAYS_EMPLOYED_DIFF_DAYS_BIRTH_SURESH</th>\n",
       "      <th>TREND_COEF_PAID_LATE_SURESH</th>\n",
       "      <th>AMT_INCOME_TOTAL_12_AMT_ANNUITY_SURESH</th>\n",
       "      <th>EXT_SOURCE_3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.000009</td>\n",
       "      <td>-0.000015</td>\n",
       "      <td>-0.000028</td>\n",
       "      <td>0.0</td>\n",
       "      <td>55597.5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-12.0</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-12.0</td>\n",
       "      <td>0.25</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>-20.421053</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8824.0</td>\n",
       "      <td>0.157343</td>\n",
       "      <td>-7825.5</td>\n",
       "      <td>0.139376</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.000019</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.000037</td>\n",
       "      <td>0.0</td>\n",
       "      <td>164002.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-4.428571</td>\n",
       "      <td>NaN</td>\n",
       "      <td>15577.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-13198.5</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.000038</td>\n",
       "      <td>-0.000029</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-7.666667</td>\n",
       "      <td>NaN</td>\n",
       "      <td>18821.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-1125.0</td>\n",
       "      <td>0.729567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.000034</td>\n",
       "      <td>0.0</td>\n",
       "      <td>15682.5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.111111</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>7.919033</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-4.500000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>15966.0</td>\n",
       "      <td>1.181081</td>\n",
       "      <td>-18436.5</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.000016</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.205607</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-2.250000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>16894.0</td>\n",
       "      <td>-0.504714</td>\n",
       "      <td>-11740.5</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   EXT_1_DIV_BIRTH_SURESH  EXT_3_DIV_BIRTH_SURESH  EXT_2_DIV_BIRTH_SURESH  \\\n",
       "0               -0.000009               -0.000015               -0.000028   \n",
       "1               -0.000019                     NaN               -0.000037   \n",
       "2                     NaN               -0.000038               -0.000029   \n",
       "3                     NaN                     NaN               -0.000034   \n",
       "4                     NaN                     NaN               -0.000016   \n",
       "\n",
       "   INSTALLMENT_PAID_LATE_LAST_LOAN_MEAN_SURESH  \\\n",
       "0                                          0.0   \n",
       "1                                          0.0   \n",
       "2                                          0.0   \n",
       "3                                          0.0   \n",
       "4                                          0.0   \n",
       "\n",
       "   AMT_CREDIT_DIFF_AMT_GOODS_SURESH  BUREAU_DEBT_CREDIT_RATIO_SURESH  \\\n",
       "0                           55597.5                              NaN   \n",
       "1                          164002.5                              0.0   \n",
       "2                               0.0                              0.0   \n",
       "3                           15682.5                              NaN   \n",
       "4                               0.0                              0.0   \n",
       "\n",
       "   PREVIOUS_APPLICATION_FRACTION_OF_REFUSED_APPLICATIONS_SURESH  \\\n",
       "0                                           0.000000              \n",
       "1                                           0.000000              \n",
       "2                                           0.000000              \n",
       "3                                           0.111111              \n",
       "4                                           0.000000              \n",
       "\n",
       "   INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_MAX_SURESH  \\\n",
       "0                                            -12.0   \n",
       "1                                             -3.0   \n",
       "2                                             -3.0   \n",
       "3                                             -1.0   \n",
       "4                                              0.0   \n",
       "\n",
       "   TREND_INTER_FUTURE_CNT_SURESH  TREND_COEF_DPD_DEF_SURESH      ...       \\\n",
       "0                       5.000000                        0.0      ...        \n",
       "1                       0.000000                        0.0      ...        \n",
       "2                            NaN                        0.0      ...        \n",
       "3                       7.919033                        0.0      ...        \n",
       "4                      20.205607                        0.0      ...        \n",
       "\n",
       "   INSTALLMENT_PAID_LATE_IN_DAYS_12_MONTHS_MAX_SURESH  \\\n",
       "0                                              -12.0    \n",
       "1                                                NaN    \n",
       "2                                                NaN    \n",
       "3                                               -1.0    \n",
       "4                                                0.0    \n",
       "\n",
       "   BUREAU_CREDIT_ACTIVE_BINARY_MEAN_SURESH DEF_30_60_SOCIAL_SUM_SURESH  \\\n",
       "0                                     0.25                           4   \n",
       "1                                     0.25                           0   \n",
       "2                                     0.00                           0   \n",
       "3                                      NaN                           0   \n",
       "4                                     0.00                           0   \n",
       "\n",
       "   POPULAR_AMT_GOODS_PRICE_SURESH  \\\n",
       "0                               0   \n",
       "1                               0   \n",
       "2                               0   \n",
       "3                               0   \n",
       "4                               0   \n",
       "\n",
       "   INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_MEAN_SURESH  MEAN_PAYMENT_CC_SURESH  \\\n",
       "0                                        -20.421053                     NaN   \n",
       "1                                         -4.428571                     NaN   \n",
       "2                                         -7.666667                     NaN   \n",
       "3                                         -4.500000                     0.0   \n",
       "4                                         -2.250000                     NaN   \n",
       "\n",
       "   DAYS_EMPLOYED_DIFF_DAYS_BIRTH_SURESH  TREND_COEF_PAID_LATE_SURESH  \\\n",
       "0                                8824.0                     0.157343   \n",
       "1                               15577.0                          NaN   \n",
       "2                               18821.0                          NaN   \n",
       "3                               15966.0                     1.181081   \n",
       "4                               16894.0                    -0.504714   \n",
       "\n",
       "   AMT_INCOME_TOTAL_12_AMT_ANNUITY_SURESH  EXT_SOURCE_3  \n",
       "0                                 -7825.5      0.139376  \n",
       "1                                -13198.5           NaN  \n",
       "2                                 -1125.0      0.729567  \n",
       "3                                -18436.5           NaN  \n",
       "4                                -11740.5           NaN  \n",
       "\n",
       "[5 rows x 26 columns]"
      ]
     },
     "execution_count": 159,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_features.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "metadata": {},
   "outputs": [],
   "source": [
    "my_features = [f for f in selected_features if f not in new_features.columns]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['AMT_ANNUITY',\n",
       " 'AMT_CREDIT',\n",
       " 'AMT_INCOME_TOTAL',\n",
       " 'NEW_CREDIT_TO_ANNUITY_RATIO',\n",
       " 'NEW_CREDIT_TO_GOODS_RATIO',\n",
       " 'NEW_CREDIT_TO_INCOME_RATIO',\n",
       " 'x_0',\n",
       " 'x_1',\n",
       " 'x_2',\n",
       " 'x_3',\n",
       " 'x_4',\n",
       " 'x_5',\n",
       " 'x_6',\n",
       " 'x_7',\n",
       " 'x_8',\n",
       " 'x_9',\n",
       " 'x_10',\n",
       " 'retirement_age',\n",
       " 'long_employment',\n",
       " 'EXT_SOURCE_1',\n",
       " 'EXT_SOURCE_2']"
      ]
     },
     "execution_count": 206,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(307511, 16)"
      ]
     },
     "execution_count": 203,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_df[categorical_columns][0:n_train].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>NAME_CONTRACT_TYPE</th>\n",
       "      <th>CODE_GENDER</th>\n",
       "      <th>FLAG_OWN_CAR</th>\n",
       "      <th>FLAG_OWN_REALTY</th>\n",
       "      <th>NAME_TYPE_SUITE</th>\n",
       "      <th>NAME_INCOME_TYPE</th>\n",
       "      <th>NAME_EDUCATION_TYPE</th>\n",
       "      <th>NAME_FAMILY_STATUS</th>\n",
       "      <th>NAME_HOUSING_TYPE</th>\n",
       "      <th>OCCUPATION_TYPE</th>\n",
       "      <th>WEEKDAY_APPR_PROCESS_START</th>\n",
       "      <th>ORGANIZATION_TYPE</th>\n",
       "      <th>FONDKAPREMONT_MODE</th>\n",
       "      <th>HOUSETYPE_MODE</th>\n",
       "      <th>WALLSMATERIAL_MODE</th>\n",
       "      <th>EMERGENCYSTATE_MODE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>18</td>\n",
       "      <td>5</td>\n",
       "      <td>28</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>42</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>54</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>14</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>18</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   NAME_CONTRACT_TYPE  CODE_GENDER  FLAG_OWN_CAR  FLAG_OWN_REALTY  \\\n",
       "0                   0            0             0                1   \n",
       "1                   0            1             0                1   \n",
       "2                   0            1             1                1   \n",
       "3                   0            0             0                1   \n",
       "4                   0            1             1                0   \n",
       "\n",
       "   NAME_TYPE_SUITE  NAME_INCOME_TYPE  NAME_EDUCATION_TYPE  NAME_FAMILY_STATUS  \\\n",
       "0                6                 7                    1                   1   \n",
       "1                6                 7                    4                   1   \n",
       "2                7                 7                    1                   1   \n",
       "3                6                 7                    4                   1   \n",
       "4                6                 7                    4                   1   \n",
       "\n",
       "   NAME_HOUSING_TYPE  OCCUPATION_TYPE  WEEKDAY_APPR_PROCESS_START  \\\n",
       "0                  1               18                           5   \n",
       "1                  1                9                           0   \n",
       "2                  1                4                           1   \n",
       "3                  1               14                           6   \n",
       "4                  1               18                           0   \n",
       "\n",
       "   ORGANIZATION_TYPE  FONDKAPREMONT_MODE  HOUSETYPE_MODE  WALLSMATERIAL_MODE  \\\n",
       "0                 28                   0               0                   5   \n",
       "1                 42                   0               1                   7   \n",
       "2                 54                   0               1                   7   \n",
       "3                  5                   3               0                   4   \n",
       "4                  5                   0               1                   7   \n",
       "\n",
       "   EMERGENCYSTATE_MODE  \n",
       "0                    0  \n",
       "1                    2  \n",
       "2                    2  \n",
       "3                    0  \n",
       "4                    2  "
      ]
     },
     "execution_count": 163,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_df[categorical_columns][n_train:].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [],
   "source": [
    "suresh_august16 = pd.read_csv('../data/SureshFeaturesAug16.csv', header=0, index_col=None)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CUSTOMER_EXT1_OVERREGION_SURESH</th>\n",
       "      <th>CUSTOMER_EXT2_OVERREGION_SURESH</th>\n",
       "      <th>CUSTOMER_EXT3_OVERREGION_SURESH</th>\n",
       "      <th>EXTERNAL_SOURCE_1_MEDIAN_SURESH</th>\n",
       "      <th>EXTERNAL_SOURCE_2_MEDIAN_SURESH</th>\n",
       "      <th>EXTERNAL_SOURCE_3_MEDIAN_SURESH</th>\n",
       "      <th>REGION_POPULATION_RELATIVE_CAT_SURESH</th>\n",
       "      <th>SK_ID_CURR</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5.803887</td>\n",
       "      <td>1.889160</td>\n",
       "      <td>3.659815</td>\n",
       "      <td>0.481937</td>\n",
       "      <td>0.496752</td>\n",
       "      <td>0.510090</td>\n",
       "      <td>65</td>\n",
       "      <td>100002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.684089</td>\n",
       "      <td>0.946854</td>\n",
       "      <td>inf</td>\n",
       "      <td>0.524202</td>\n",
       "      <td>0.589176</td>\n",
       "      <td>0.506484</td>\n",
       "      <td>13</td>\n",
       "      <td>100003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>inf</td>\n",
       "      <td>0.917455</td>\n",
       "      <td>0.767969</td>\n",
       "      <td>0.462446</td>\n",
       "      <td>0.510024</td>\n",
       "      <td>0.560284</td>\n",
       "      <td>49</td>\n",
       "      <td>100004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>inf</td>\n",
       "      <td>0.826746</td>\n",
       "      <td>inf</td>\n",
       "      <td>0.503594</td>\n",
       "      <td>0.537750</td>\n",
       "      <td>0.506484</td>\n",
       "      <td>36</td>\n",
       "      <td>100006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>inf</td>\n",
       "      <td>1.695639</td>\n",
       "      <td>inf</td>\n",
       "      <td>0.523748</td>\n",
       "      <td>0.547248</td>\n",
       "      <td>0.517297</td>\n",
       "      <td>76</td>\n",
       "      <td>100007</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   CUSTOMER_EXT1_OVERREGION_SURESH  CUSTOMER_EXT2_OVERREGION_SURESH  \\\n",
       "0                         5.803887                         1.889160   \n",
       "1                         1.684089                         0.946854   \n",
       "2                              inf                         0.917455   \n",
       "3                              inf                         0.826746   \n",
       "4                              inf                         1.695639   \n",
       "\n",
       "   CUSTOMER_EXT3_OVERREGION_SURESH  EXTERNAL_SOURCE_1_MEDIAN_SURESH  \\\n",
       "0                         3.659815                         0.481937   \n",
       "1                              inf                         0.524202   \n",
       "2                         0.767969                         0.462446   \n",
       "3                              inf                         0.503594   \n",
       "4                              inf                         0.523748   \n",
       "\n",
       "   EXTERNAL_SOURCE_2_MEDIAN_SURESH  EXTERNAL_SOURCE_3_MEDIAN_SURESH  \\\n",
       "0                         0.496752                         0.510090   \n",
       "1                         0.589176                         0.506484   \n",
       "2                         0.510024                         0.560284   \n",
       "3                         0.537750                         0.506484   \n",
       "4                         0.547248                         0.517297   \n",
       "\n",
       "   REGION_POPULATION_RELATIVE_CAT_SURESH  SK_ID_CURR  \n",
       "0                                     65      100002  \n",
       "1                                     13      100003  \n",
       "2                                     49      100004  \n",
       "3                                     36      100006  \n",
       "4                                     76      100007  "
      ]
     },
     "execution_count": 165,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "suresh_august16.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {},
   "outputs": [],
   "source": [
    "del suresh_august16['SK_ID_CURR']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>AMT_GOODS_PRICE_TO_CREDIT</th>\n",
       "      <th>AMT_CREDIT_INSTALLMENTS</th>\n",
       "      <th>AMT_CREDIT_INTEREST_MAYBE</th>\n",
       "      <th>AMT_CREDIT_INTEREST_MAYBE_RAT</th>\n",
       "      <th>AMT_INCOME_TOTAL_RAT_CREDIT</th>\n",
       "      <th>NAME_CONTRACT_TYPE_Consumer_loans</th>\n",
       "      <th>NAME_CONTRACT_TYPE_Cash_loans</th>\n",
       "      <th>NAME_CONTRACT_TYPE_Revolving_loans</th>\n",
       "      <th>NAME_CONTRACT_TYPE_XNA</th>\n",
       "      <th>PRE_RECORD_COUNT</th>\n",
       "      <th>...</th>\n",
       "      <th>STCK_PAY_480_.</th>\n",
       "      <th>STCK_CC_6_.</th>\n",
       "      <th>STCK_BERBAL_6_.</th>\n",
       "      <th>EXT_MEAN</th>\n",
       "      <th>TERM_BEFORE_END</th>\n",
       "      <th>DAYS_DECISION_MEAN</th>\n",
       "      <th>AMT_CREDIT_LIMIT_ACTUAL_6</th>\n",
       "      <th>AMT_CREDIT_LIMIT_ACTUAL_12</th>\n",
       "      <th>SK_ID_CURR</th>\n",
       "      <th>IS_TRAIN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.863262</td>\n",
       "      <td>16.461104</td>\n",
       "      <td>11389.5</td>\n",
       "      <td>0.028012</td>\n",
       "      <td>0.144444</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.080736</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.160535</td>\n",
       "      <td>0.161787</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-606.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>100002</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.873211</td>\n",
       "      <td>36.234085</td>\n",
       "      <td>8356.5</td>\n",
       "      <td>0.006460</td>\n",
       "      <td>0.348611</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.0</td>\n",
       "      <td>-3915.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>100003</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.166667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-815.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>100004</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.949845</td>\n",
       "      <td>10.532818</td>\n",
       "      <td>15817.5</td>\n",
       "      <td>0.050586</td>\n",
       "      <td>0.183333</td>\n",
       "      <td>5.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.073751</td>\n",
       "      <td>0.03353</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.0</td>\n",
       "      <td>-2452.0</td>\n",
       "      <td>270000.0</td>\n",
       "      <td>270000.0</td>\n",
       "      <td>100006</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>23.461618</td>\n",
       "      <td>10093.5</td>\n",
       "      <td>0.019675</td>\n",
       "      <td>0.351852</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.076197</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.0</td>\n",
       "      <td>-7337.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>100007</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 270 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   AMT_GOODS_PRICE_TO_CREDIT  AMT_CREDIT_INSTALLMENTS  \\\n",
       "0                   0.863262                16.461104   \n",
       "1                   0.873211                36.234085   \n",
       "2                   1.000000                20.000000   \n",
       "3                   0.949845                10.532818   \n",
       "4                   1.000000                23.461618   \n",
       "\n",
       "   AMT_CREDIT_INTEREST_MAYBE  AMT_CREDIT_INTEREST_MAYBE_RAT  \\\n",
       "0                    11389.5                       0.028012   \n",
       "1                     8356.5                       0.006460   \n",
       "2                        0.0                       0.000000   \n",
       "3                    15817.5                       0.050586   \n",
       "4                    10093.5                       0.019675   \n",
       "\n",
       "   AMT_INCOME_TOTAL_RAT_CREDIT  NAME_CONTRACT_TYPE_Consumer_loans  \\\n",
       "0                     0.144444                                0.0   \n",
       "1                     0.348611                                1.0   \n",
       "2                     0.166667                                0.0   \n",
       "3                     0.183333                                5.0   \n",
       "4                     0.351852                                4.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE_Cash_loans  NAME_CONTRACT_TYPE_Revolving_loans  \\\n",
       "0                            1.0                                 0.0   \n",
       "1                            2.0                                 0.0   \n",
       "2                            1.0                                 0.0   \n",
       "3                            2.0                                 2.0   \n",
       "4                            2.0                                 0.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE_XNA  PRE_RECORD_COUNT    ...     STCK_PAY_480_.  \\\n",
       "0                     0.0               1.0    ...           0.080736   \n",
       "1                     0.0               3.0    ...                NaN   \n",
       "2                     0.0               1.0    ...                NaN   \n",
       "3                     0.0               9.0    ...           0.073751   \n",
       "4                     0.0               6.0    ...           0.076197   \n",
       "\n",
       "   STCK_CC_6_.  STCK_BERBAL_6_.  EXT_MEAN  TERM_BEFORE_END  \\\n",
       "0          NaN         0.160535  0.161787              1.0   \n",
       "1          NaN              NaN       NaN              3.0   \n",
       "2          NaN              NaN       NaN              1.0   \n",
       "3      0.03353              NaN       NaN              2.0   \n",
       "4          NaN              NaN       NaN              4.0   \n",
       "\n",
       "   DAYS_DECISION_MEAN  AMT_CREDIT_LIMIT_ACTUAL_6  AMT_CREDIT_LIMIT_ACTUAL_12  \\\n",
       "0              -606.0                        NaN                         NaN   \n",
       "1             -3915.0                        NaN                         NaN   \n",
       "2              -815.0                        NaN                         NaN   \n",
       "3             -2452.0                   270000.0                    270000.0   \n",
       "4             -7337.0                        NaN                         NaN   \n",
       "\n",
       "   SK_ID_CURR  IS_TRAIN  \n",
       "0      100002         1  \n",
       "1      100003         1  \n",
       "2      100004         1  \n",
       "3      100006         1  \n",
       "4      100007         1  \n",
       "\n",
       "[5 rows x 270 columns]"
      ]
     },
     "execution_count": 167,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "goran_features = pd.read_csv('../goran-data/goranm_feats_v3.csv', header=0, index_col=None)\n",
    "goran_features.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [],
   "source": [
    "del goran_features['SK_ID_CURR']\n",
    "del goran_features['IS_TRAIN']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {},
   "outputs": [],
   "source": [
    "goran_features_19_8 = pd.read_csv('../data/goranm_feats_19_08.csv', header=0, index_col=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>AMT_INCOME_TO_REGION_MEAN</th>\n",
       "      <th>EXT_3_TO_REGION_MEAN</th>\n",
       "      <th>EXT_2_TO_REGION_MEAN</th>\n",
       "      <th>EXT_1_TO_REGION_MEAN</th>\n",
       "      <th>AMT_CREDIT_INSTALLMENTS_TO_REGION_MEAN</th>\n",
       "      <th>AMT_INCOME_TOTAL_RAT_CREDIT_TO_REGION_MEAN</th>\n",
       "      <th>MEAN_CREDIT_DURATION_TO_REGION_MEAN</th>\n",
       "      <th>MAX_DAYS_LAST_DUE_TO_REGION_MEAN</th>\n",
       "      <th>SK_ID_CURR</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.144653</td>\n",
       "      <td>0.286892</td>\n",
       "      <td>0.591183</td>\n",
       "      <td>0.171547</td>\n",
       "      <td>0.769676</td>\n",
       "      <td>0.505468</td>\n",
       "      <td>0.403411</td>\n",
       "      <td>-0.000140</td>\n",
       "      <td>100002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.124447</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.152353</td>\n",
       "      <td>0.605032</td>\n",
       "      <td>1.554841</td>\n",
       "      <td>1.221852</td>\n",
       "      <td>0.441247</td>\n",
       "      <td>-0.004194</td>\n",
       "      <td>100003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.357478</td>\n",
       "      <td>1.364991</td>\n",
       "      <td>1.188570</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.982184</td>\n",
       "      <td>0.637138</td>\n",
       "      <td>0.203086</td>\n",
       "      <td>-0.004140</td>\n",
       "      <td>100004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.739426</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.266580</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.494683</td>\n",
       "      <td>0.697055</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.983986</td>\n",
       "      <td>100006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.795062</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.641314</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.132934</td>\n",
       "      <td>1.132543</td>\n",
       "      <td>0.185846</td>\n",
       "      <td>2.215766</td>\n",
       "      <td>100007</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   AMT_INCOME_TO_REGION_MEAN  EXT_3_TO_REGION_MEAN  EXT_2_TO_REGION_MEAN  \\\n",
       "0                   1.144653              0.286892              0.591183   \n",
       "1                   1.124447                   NaN              1.152353   \n",
       "2                   0.357478              1.364991              1.188570   \n",
       "3                   0.739426                   NaN              1.266580   \n",
       "4                   0.795062                   NaN              0.641314   \n",
       "\n",
       "   EXT_1_TO_REGION_MEAN  AMT_CREDIT_INSTALLMENTS_TO_REGION_MEAN  \\\n",
       "0              0.171547                                0.769676   \n",
       "1              0.605032                                1.554841   \n",
       "2                   NaN                                0.982184   \n",
       "3                   NaN                                0.494683   \n",
       "4                   NaN                                1.132934   \n",
       "\n",
       "   AMT_INCOME_TOTAL_RAT_CREDIT_TO_REGION_MEAN  \\\n",
       "0                                    0.505468   \n",
       "1                                    1.221852   \n",
       "2                                    0.637138   \n",
       "3                                    0.697055   \n",
       "4                                    1.132543   \n",
       "\n",
       "   MEAN_CREDIT_DURATION_TO_REGION_MEAN  MAX_DAYS_LAST_DUE_TO_REGION_MEAN  \\\n",
       "0                             0.403411                         -0.000140   \n",
       "1                             0.441247                         -0.004194   \n",
       "2                             0.203086                         -0.004140   \n",
       "3                                  NaN                          1.983986   \n",
       "4                             0.185846                          2.215766   \n",
       "\n",
       "   SK_ID_CURR  \n",
       "0      100002  \n",
       "1      100003  \n",
       "2      100004  \n",
       "3      100006  \n",
       "4      100007  "
      ]
     },
     "execution_count": 170,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "goran_features_19_8.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "metadata": {},
   "outputs": [],
   "source": [
    "del goran_features_19_8['SK_ID_CURR']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.externals import joblib\n",
    "\n",
    "prevs_df = joblib.load('../data/prev_application_solution3_v2')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SK_ID_CURR</th>\n",
       "      <th>prev_application_solution3_v2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100002</td>\n",
       "      <td>0.115430</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100003</td>\n",
       "      <td>0.019078</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100004</td>\n",
       "      <td>0.084967</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100006</td>\n",
       "      <td>0.123526</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>100007</td>\n",
       "      <td>0.098192</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   SK_ID_CURR  prev_application_solution3_v2\n",
       "0      100002                       0.115430\n",
       "1      100003                       0.019078\n",
       "2      100004                       0.084967\n",
       "3      100006                       0.123526\n",
       "4      100007                       0.098192"
      ]
     },
     "execution_count": 173,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prevs_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "metadata": {},
   "outputs": [],
   "source": [
    "suresh_august16_2 = pd.read_csv('../data/SureshFeaturesAug16_2.csv', header=0, index_col=None)\n",
    "suresh_august15 = pd.read_csv('../data/SureshFeaturesAug15.csv', header=0, index_col=None)\n",
    "suresh_august16 = pd.read_csv('../data/SureshFeaturesAug16.csv', header=0, index_col=None)\n",
    "suresh_august19 = pd.read_csv('../data/suresh_features_Aug19th.csv', header=0, index_col=None)\n",
    "suresh_august19_2 = pd.read_csv('../data/SureshFeatures_19_2th.csv', header=0, index_col=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "metadata": {},
   "outputs": [],
   "source": [
    "suresh_august20 = pd.read_csv('../data/SureshFeatures3BestAgu20.csv', header=0, index_col=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SK_ID_CURR</th>\n",
       "      <th>PAYMENT_FEATURE_1_SURESH</th>\n",
       "      <th>PAYMENT_FEATURE_2_SURESH</th>\n",
       "      <th>PAYMENT_FEATURE_3_SURESH</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100002</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100003</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100004</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100006</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>100007</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>100008</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>100009</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>100010</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>100011</td>\n",
       "      <td>2.384618</td>\n",
       "      <td>149254.425</td>\n",
       "      <td>74627.2125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>100012</td>\n",
       "      <td>0.399495</td>\n",
       "      <td>4417.425</td>\n",
       "      <td>4417.4250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>100014</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>100015</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>100016</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>100017</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>100018</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>100019</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>100020</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>100021</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>100022</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>100023</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>100024</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>100025</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>100026</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>100027</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>100029</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>100030</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>100031</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>100032</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>100033</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>100034</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>100082</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>100083</td>\n",
       "      <td>2.056877</td>\n",
       "      <td>24507.900</td>\n",
       "      <td>24507.9000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>100084</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>100085</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>100086</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>100087</td>\n",
       "      <td>4.481624</td>\n",
       "      <td>149080.365</td>\n",
       "      <td>74540.1825</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>100088</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>100089</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>100093</td>\n",
       "      <td>1.786632</td>\n",
       "      <td>14604.300</td>\n",
       "      <td>14604.3000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>100094</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>100095</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>100096</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>100097</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>100098</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>100099</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>100100</td>\n",
       "      <td>1.796613</td>\n",
       "      <td>195932.115</td>\n",
       "      <td>39186.4230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>100101</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>100102</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>100103</td>\n",
       "      <td>2.072092</td>\n",
       "      <td>58483.080</td>\n",
       "      <td>9747.1800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>100104</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>100105</td>\n",
       "      <td>2.812253</td>\n",
       "      <td>598093.785</td>\n",
       "      <td>119618.7570</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>100108</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>100110</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>100111</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>100112</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>14844.555</td>\n",
       "      <td>14844.5550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>100113</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>100114</td>\n",
       "      <td>2.900064</td>\n",
       "      <td>96586.740</td>\n",
       "      <td>24146.6850</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>100115</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>100116</td>\n",
       "      <td>1.500000</td>\n",
       "      <td>47250.000</td>\n",
       "      <td>23625.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>100118</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    SK_ID_CURR  PAYMENT_FEATURE_1_SURESH  PAYMENT_FEATURE_2_SURESH  \\\n",
       "0       100002                       NaN                       NaN   \n",
       "1       100003                       NaN                       NaN   \n",
       "2       100004                       NaN                       NaN   \n",
       "3       100006                       NaN                       NaN   \n",
       "4       100007                       NaN                       NaN   \n",
       "5       100008                       NaN                       NaN   \n",
       "6       100009                       NaN                       NaN   \n",
       "7       100010                       NaN                       NaN   \n",
       "8       100011                  2.384618                149254.425   \n",
       "9       100012                  0.399495                  4417.425   \n",
       "10      100014                       NaN                       NaN   \n",
       "11      100015                       NaN                       NaN   \n",
       "12      100016                       NaN                       NaN   \n",
       "13      100017                       NaN                       NaN   \n",
       "14      100018                       NaN                       NaN   \n",
       "15      100019                       NaN                       NaN   \n",
       "16      100020                       NaN                       NaN   \n",
       "17      100021                       NaN                       NaN   \n",
       "18      100022                       NaN                       NaN   \n",
       "19      100023                       NaN                       NaN   \n",
       "20      100024                       NaN                       NaN   \n",
       "21      100025                       NaN                       NaN   \n",
       "22      100026                       NaN                       NaN   \n",
       "23      100027                       NaN                       NaN   \n",
       "24      100029                       NaN                       NaN   \n",
       "25      100030                       NaN                       NaN   \n",
       "26      100031                       NaN                       NaN   \n",
       "27      100032                       NaN                       NaN   \n",
       "28      100033                       NaN                       NaN   \n",
       "29      100034                       NaN                       NaN   \n",
       "..         ...                       ...                       ...   \n",
       "70      100082                       NaN                       NaN   \n",
       "71      100083                  2.056877                 24507.900   \n",
       "72      100084                       NaN                       NaN   \n",
       "73      100085                       NaN                       NaN   \n",
       "74      100086                       NaN                       NaN   \n",
       "75      100087                  4.481624                149080.365   \n",
       "76      100088                       NaN                       NaN   \n",
       "77      100089                       NaN                       NaN   \n",
       "78      100093                  1.786632                 14604.300   \n",
       "79      100094                       NaN                       NaN   \n",
       "80      100095                       NaN                       NaN   \n",
       "81      100096                       NaN                       NaN   \n",
       "82      100097                       NaN                       NaN   \n",
       "83      100098                       NaN                       NaN   \n",
       "84      100099                       NaN                       NaN   \n",
       "85      100100                  1.796613                195932.115   \n",
       "86      100101                       NaN                       NaN   \n",
       "87      100102                       NaN                       NaN   \n",
       "88      100103                  2.072092                 58483.080   \n",
       "89      100104                       NaN                       NaN   \n",
       "90      100105                  2.812253                598093.785   \n",
       "91      100108                       NaN                       NaN   \n",
       "92      100110                       NaN                       NaN   \n",
       "93      100111                       NaN                       NaN   \n",
       "94      100112                  1.000000                 14844.555   \n",
       "95      100113                       NaN                       NaN   \n",
       "96      100114                  2.900064                 96586.740   \n",
       "97      100115                       NaN                       NaN   \n",
       "98      100116                  1.500000                 47250.000   \n",
       "99      100118                       NaN                       NaN   \n",
       "\n",
       "    PAYMENT_FEATURE_3_SURESH  \n",
       "0                        NaN  \n",
       "1                        NaN  \n",
       "2                        NaN  \n",
       "3                        NaN  \n",
       "4                        NaN  \n",
       "5                        NaN  \n",
       "6                        NaN  \n",
       "7                        NaN  \n",
       "8                 74627.2125  \n",
       "9                  4417.4250  \n",
       "10                       NaN  \n",
       "11                       NaN  \n",
       "12                       NaN  \n",
       "13                       NaN  \n",
       "14                       NaN  \n",
       "15                       NaN  \n",
       "16                       NaN  \n",
       "17                       NaN  \n",
       "18                       NaN  \n",
       "19                       NaN  \n",
       "20                       NaN  \n",
       "21                       NaN  \n",
       "22                       NaN  \n",
       "23                       NaN  \n",
       "24                       NaN  \n",
       "25                       NaN  \n",
       "26                       NaN  \n",
       "27                       NaN  \n",
       "28                       NaN  \n",
       "29                       NaN  \n",
       "..                       ...  \n",
       "70                       NaN  \n",
       "71                24507.9000  \n",
       "72                       NaN  \n",
       "73                       NaN  \n",
       "74                       NaN  \n",
       "75                74540.1825  \n",
       "76                       NaN  \n",
       "77                       NaN  \n",
       "78                14604.3000  \n",
       "79                       NaN  \n",
       "80                       NaN  \n",
       "81                       NaN  \n",
       "82                       NaN  \n",
       "83                       NaN  \n",
       "84                       NaN  \n",
       "85                39186.4230  \n",
       "86                       NaN  \n",
       "87                       NaN  \n",
       "88                 9747.1800  \n",
       "89                       NaN  \n",
       "90               119618.7570  \n",
       "91                       NaN  \n",
       "92                       NaN  \n",
       "93                       NaN  \n",
       "94                14844.5550  \n",
       "95                       NaN  \n",
       "96                24146.6850  \n",
       "97                       NaN  \n",
       "98                23625.0000  \n",
       "99                       NaN  \n",
       "\n",
       "[100 rows x 4 columns]"
      ]
     },
     "execution_count": 176,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "suresh_august20.head(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>NUM_ACTIVE_CASH_LOANS_SURESH</th>\n",
       "      <th>NO_ACTIVE_CC_LOANS_SURESH</th>\n",
       "      <th>FUTURE_CASH_INSTALLMENTS_SUM_SURESH</th>\n",
       "      <th>MEAN_DPD_6MONTHS_CASH_LOANS_SURESH</th>\n",
       "      <th>TOTAL_PREV_CASH_LOANS_SURESH</th>\n",
       "      <th>TOTAL_PREV_REVO_LOANS_SURESH</th>\n",
       "      <th>PER_X_SELL_LOANS_SURESH</th>\n",
       "      <th>TOTAL_WALK_IN_LOANS_SURESH</th>\n",
       "      <th>PER_WALK_IN_LOANS_SURESH</th>\n",
       "      <th>TOTAL_CC_PAYMENTS_SURESH</th>\n",
       "      <th>...</th>\n",
       "      <th>AMT_INCOME_TOTAL_12_AMT_ANNUITY_2_SURESH</th>\n",
       "      <th>TOTAL_CC_LOADING_6MONTHS_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_LATE_IN_DAYS_12_MONTHS_SUM_SURESH</th>\n",
       "      <th>COUNT_SCOFR_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_OVER_AMOUNT_LAST_LOAN_MEAN_SURESH</th>\n",
       "      <th>CREDIT_PER_NON_CHILD_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_SD_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_SUM_SURESH</th>\n",
       "      <th>MEAN_PAYMENT_CC_SURESH</th>\n",
       "      <th>DAYS_DECISION_MAX_SURESH</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-211.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>406597.50</td>\n",
       "      <td>4.925171</td>\n",
       "      <td>-388.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-606.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>646751.25</td>\n",
       "      <td>1.718249</td>\n",
       "      <td>-31.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-746.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>135000.00</td>\n",
       "      <td>4.163332</td>\n",
       "      <td>-23.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-815.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.600000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-18436.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-68.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>156341.25</td>\n",
       "      <td>3.628590</td>\n",
       "      <td>-45.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-181.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>13.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.166667</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-47.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>513000.00</td>\n",
       "      <td>1.422226</td>\n",
       "      <td>-27.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-374.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   NUM_ACTIVE_CASH_LOANS_SURESH  NO_ACTIVE_CC_LOANS_SURESH  \\\n",
       "0                           1.0                        NaN   \n",
       "1                           3.0                        NaN   \n",
       "2                           1.0                        NaN   \n",
       "3                           3.0                        1.0   \n",
       "4                           5.0                        NaN   \n",
       "\n",
       "   FUTURE_CASH_INSTALLMENTS_SUM_SURESH  MEAN_DPD_6MONTHS_CASH_LOANS_SURESH  \\\n",
       "0                                  6.0                                 0.0   \n",
       "1                                  NaN                                 NaN   \n",
       "2                                  NaN                                 NaN   \n",
       "3                                  3.0                                 0.0   \n",
       "4                                 13.0                                 0.0   \n",
       "\n",
       "   TOTAL_PREV_CASH_LOANS_SURESH  TOTAL_PREV_REVO_LOANS_SURESH  \\\n",
       "0                           NaN                           NaN   \n",
       "1                           1.0                           NaN   \n",
       "2                           NaN                           NaN   \n",
       "3                           2.0                           1.0   \n",
       "4                           4.0                           NaN   \n",
       "\n",
       "   PER_X_SELL_LOANS_SURESH  TOTAL_WALK_IN_LOANS_SURESH  \\\n",
       "0                 0.000000                         0.0   \n",
       "1                 0.333333                         0.0   \n",
       "2                 0.000000                         0.0   \n",
       "3                 0.600000                         0.0   \n",
       "4                 0.500000                         1.0   \n",
       "\n",
       "   PER_WALK_IN_LOANS_SURESH  TOTAL_CC_PAYMENTS_SURESH  \\\n",
       "0                  0.000000                       NaN   \n",
       "1                  0.000000                       NaN   \n",
       "2                  0.000000                       NaN   \n",
       "3                  0.000000                       0.0   \n",
       "4                  0.166667                       NaN   \n",
       "\n",
       "             ...             AMT_INCOME_TOTAL_12_AMT_ANNUITY_2_SURESH  \\\n",
       "0            ...                                                  NaN   \n",
       "1            ...                                                  NaN   \n",
       "2            ...                                                  NaN   \n",
       "3            ...                                             -18436.5   \n",
       "4            ...                                                  NaN   \n",
       "\n",
       "   TOTAL_CC_LOADING_6MONTHS_SURESH  \\\n",
       "0                              NaN   \n",
       "1                              NaN   \n",
       "2                              NaN   \n",
       "3                              0.0   \n",
       "4                              NaN   \n",
       "\n",
       "   INSTALLMENT_PAID_LATE_IN_DAYS_12_MONTHS_SUM_SURESH  COUNT_SCOFR_SURESH  \\\n",
       "0                                             -211.0                  NaN   \n",
       "1                                                NaN                  NaN   \n",
       "2                                                NaN                  NaN   \n",
       "3                                              -68.0                  NaN   \n",
       "4                                              -47.0                  NaN   \n",
       "\n",
       "   INSTALLMENT_PAID_OVER_AMOUNT_LAST_LOAN_MEAN_SURESH  \\\n",
       "0                                                0.0    \n",
       "1                                                0.0    \n",
       "2                                                0.0    \n",
       "3                                                0.0    \n",
       "4                                                0.0    \n",
       "\n",
       "   CREDIT_PER_NON_CHILD_SURESH  \\\n",
       "0                    406597.50   \n",
       "1                    646751.25   \n",
       "2                    135000.00   \n",
       "3                    156341.25   \n",
       "4                    513000.00   \n",
       "\n",
       "   INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_SD_SURESH  \\\n",
       "0                                        4.925171   \n",
       "1                                        1.718249   \n",
       "2                                        4.163332   \n",
       "3                                        3.628590   \n",
       "4                                        1.422226   \n",
       "\n",
       "   INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_SUM_SURESH  MEAN_PAYMENT_CC_SURESH  \\\n",
       "0                                           -388.0                     NaN   \n",
       "1                                            -31.0                     NaN   \n",
       "2                                            -23.0                     NaN   \n",
       "3                                            -45.0                     0.0   \n",
       "4                                            -27.0                     NaN   \n",
       "\n",
       "   DAYS_DECISION_MAX_SURESH  \n",
       "0                    -606.0  \n",
       "1                    -746.0  \n",
       "2                    -815.0  \n",
       "3                    -181.0  \n",
       "4                    -374.0  \n",
       "\n",
       "[5 rows x 21 columns]"
      ]
     },
     "execution_count": 177,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del suresh_august15['SK_ID_CURR']\n",
    "del suresh_august16_2['SK_ID_CURR']\n",
    "del suresh_august19['SK_ID_CURR_SURESH']\n",
    "del suresh_august16['SK_ID_CURR']\n",
    "del suresh_august19_2['SK_ID_CURR']\n",
    "suresh_august15.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "metadata": {},
   "outputs": [],
   "source": [
    "suresh_20 = pd.read_csv('../data/SureshFeatures20_2.csv', header=0, index_col=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SK_ID_CURR</th>\n",
       "      <th>PAYMENT_FEATURE_4_SURESH</th>\n",
       "      <th>PAYMENT_FEATURE_5_SURESH</th>\n",
       "      <th>PAYMENT_FEATURE_6_SURESH</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100002</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100003</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100004</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100006</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>100007</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>100008</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>100009</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>100010</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>100011</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>100012</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>100014</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>100015</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>100016</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>100017</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>100018</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>100019</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>100020</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>100021</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>100022</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>100023</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>100024</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>100025</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>100026</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>100027</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>100029</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>100030</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>100031</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>100032</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>100033</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>100034</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>100082</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>100083</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>100084</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>100085</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>100086</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>100087</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>100088</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>100089</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>100093</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>100094</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>100095</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>100096</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>100097</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>100098</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>100099</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>100100</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>100101</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>100102</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>100103</td>\n",
       "      <td>5.984801</td>\n",
       "      <td>56305.215</td>\n",
       "      <td>28152.6075</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>100104</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>100105</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>100108</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>100110</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>100111</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>100112</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>100113</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>100114</td>\n",
       "      <td>2.393119</td>\n",
       "      <td>39851.460</td>\n",
       "      <td>19925.7300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>100115</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>100116</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>100118</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    SK_ID_CURR  PAYMENT_FEATURE_4_SURESH  PAYMENT_FEATURE_5_SURESH  \\\n",
       "0       100002                       NaN                       NaN   \n",
       "1       100003                       NaN                       NaN   \n",
       "2       100004                       NaN                       NaN   \n",
       "3       100006                       NaN                       NaN   \n",
       "4       100007                       NaN                       NaN   \n",
       "5       100008                       NaN                       NaN   \n",
       "6       100009                       NaN                       NaN   \n",
       "7       100010                       NaN                       NaN   \n",
       "8       100011                       NaN                       NaN   \n",
       "9       100012                       NaN                       NaN   \n",
       "10      100014                       NaN                       NaN   \n",
       "11      100015                       NaN                       NaN   \n",
       "12      100016                       NaN                       NaN   \n",
       "13      100017                       NaN                       NaN   \n",
       "14      100018                       NaN                       NaN   \n",
       "15      100019                       NaN                       NaN   \n",
       "16      100020                       NaN                       NaN   \n",
       "17      100021                       NaN                       NaN   \n",
       "18      100022                       NaN                       NaN   \n",
       "19      100023                       NaN                       NaN   \n",
       "20      100024                       NaN                       NaN   \n",
       "21      100025                       NaN                       NaN   \n",
       "22      100026                       NaN                       NaN   \n",
       "23      100027                       NaN                       NaN   \n",
       "24      100029                       NaN                       NaN   \n",
       "25      100030                       NaN                       NaN   \n",
       "26      100031                       NaN                       NaN   \n",
       "27      100032                       NaN                       NaN   \n",
       "28      100033                       NaN                       NaN   \n",
       "29      100034                       NaN                       NaN   \n",
       "..         ...                       ...                       ...   \n",
       "70      100082                       NaN                       NaN   \n",
       "71      100083                       NaN                       NaN   \n",
       "72      100084                       NaN                       NaN   \n",
       "73      100085                       NaN                       NaN   \n",
       "74      100086                       NaN                       NaN   \n",
       "75      100087                       NaN                       NaN   \n",
       "76      100088                       NaN                       NaN   \n",
       "77      100089                       NaN                       NaN   \n",
       "78      100093                       NaN                       NaN   \n",
       "79      100094                       NaN                       NaN   \n",
       "80      100095                       NaN                       NaN   \n",
       "81      100096                       NaN                       NaN   \n",
       "82      100097                       NaN                       NaN   \n",
       "83      100098                       NaN                       NaN   \n",
       "84      100099                       NaN                       NaN   \n",
       "85      100100                       NaN                       NaN   \n",
       "86      100101                       NaN                       NaN   \n",
       "87      100102                       NaN                       NaN   \n",
       "88      100103                  5.984801                 56305.215   \n",
       "89      100104                       NaN                       NaN   \n",
       "90      100105                       NaN                       NaN   \n",
       "91      100108                       NaN                       NaN   \n",
       "92      100110                       NaN                       NaN   \n",
       "93      100111                       NaN                       NaN   \n",
       "94      100112                       NaN                       NaN   \n",
       "95      100113                       NaN                       NaN   \n",
       "96      100114                  2.393119                 39851.460   \n",
       "97      100115                       NaN                       NaN   \n",
       "98      100116                       NaN                       NaN   \n",
       "99      100118                       NaN                       NaN   \n",
       "\n",
       "    PAYMENT_FEATURE_6_SURESH  \n",
       "0                        NaN  \n",
       "1                        NaN  \n",
       "2                        NaN  \n",
       "3                        NaN  \n",
       "4                        NaN  \n",
       "5                        NaN  \n",
       "6                        NaN  \n",
       "7                        NaN  \n",
       "8                        NaN  \n",
       "9                        NaN  \n",
       "10                       NaN  \n",
       "11                       NaN  \n",
       "12                       NaN  \n",
       "13                       NaN  \n",
       "14                       NaN  \n",
       "15                       NaN  \n",
       "16                       NaN  \n",
       "17                       NaN  \n",
       "18                       NaN  \n",
       "19                       NaN  \n",
       "20                       NaN  \n",
       "21                       NaN  \n",
       "22                       NaN  \n",
       "23                       NaN  \n",
       "24                       NaN  \n",
       "25                       NaN  \n",
       "26                       NaN  \n",
       "27                       NaN  \n",
       "28                       NaN  \n",
       "29                       NaN  \n",
       "..                       ...  \n",
       "70                       NaN  \n",
       "71                       NaN  \n",
       "72                       NaN  \n",
       "73                       NaN  \n",
       "74                       NaN  \n",
       "75                       NaN  \n",
       "76                       NaN  \n",
       "77                       NaN  \n",
       "78                       NaN  \n",
       "79                       NaN  \n",
       "80                       NaN  \n",
       "81                       NaN  \n",
       "82                       NaN  \n",
       "83                       NaN  \n",
       "84                       NaN  \n",
       "85                       NaN  \n",
       "86                       NaN  \n",
       "87                       NaN  \n",
       "88                28152.6075  \n",
       "89                       NaN  \n",
       "90                       NaN  \n",
       "91                       NaN  \n",
       "92                       NaN  \n",
       "93                       NaN  \n",
       "94                       NaN  \n",
       "95                       NaN  \n",
       "96                19925.7300  \n",
       "97                       NaN  \n",
       "98                       NaN  \n",
       "99                       NaN  \n",
       "\n",
       "[100 rows x 4 columns]"
      ]
     },
     "execution_count": 179,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "suresh_20.head(100)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {},
   "outputs": [],
   "source": [
    "del suresh_20['SK_ID_CURR']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {},
   "outputs": [],
   "source": [
    "goranm_8_20 = pd.read_csv('../data/goranm_08_20.csv', header=0, index_col=None)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MAYBE_START_OF_APPLICATION</th>\n",
       "      <th>DAYS_CURRENT_END</th>\n",
       "      <th>AGE_AT_END_OF_LOAND</th>\n",
       "      <th>MEAN_OVERDUE_CORRECTED</th>\n",
       "      <th>SK_ID_CURR</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-606.0</td>\n",
       "      <td>-112.166879</td>\n",
       "      <td>25.920548</td>\n",
       "      <td>150.0</td>\n",
       "      <td>100002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-291.0</td>\n",
       "      <td>796.022564</td>\n",
       "      <td>48.112391</td>\n",
       "      <td>50.0</td>\n",
       "      <td>100003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-225.0</td>\n",
       "      <td>375.000000</td>\n",
       "      <td>53.208219</td>\n",
       "      <td>30.0</td>\n",
       "      <td>100004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-181.0</td>\n",
       "      <td>134.984538</td>\n",
       "      <td>52.438314</td>\n",
       "      <td>NaN</td>\n",
       "      <td>100006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-374.0</td>\n",
       "      <td>329.848529</td>\n",
       "      <td>55.511914</td>\n",
       "      <td>NaN</td>\n",
       "      <td>100007</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   MAYBE_START_OF_APPLICATION  DAYS_CURRENT_END  AGE_AT_END_OF_LOAND  \\\n",
       "0                      -606.0       -112.166879            25.920548   \n",
       "1                      -291.0        796.022564            48.112391   \n",
       "2                      -225.0        375.000000            53.208219   \n",
       "3                      -181.0        134.984538            52.438314   \n",
       "4                      -374.0        329.848529            55.511914   \n",
       "\n",
       "   MEAN_OVERDUE_CORRECTED  SK_ID_CURR  \n",
       "0                   150.0      100002  \n",
       "1                    50.0      100003  \n",
       "2                    30.0      100004  \n",
       "3                     NaN      100006  \n",
       "4                     NaN      100007  "
      ]
     },
     "execution_count": 182,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "goranm_8_20.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "metadata": {},
   "outputs": [],
   "source": [
    "del goranm_8_20['SK_ID_CURR']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "metadata": {},
   "outputs": [],
   "source": [
    "def do_countuniq( df, group_cols, counted, agg_name, agg_type='uint32', show_max=False, show_agg=True ):\n",
    "    if show_agg:\n",
    "        print( \"Counting unqiue \", counted, \" by \", group_cols , '...' )\n",
    "    gp = df[group_cols+[counted]].groupby(group_cols)[counted].nunique().reset_index().rename(columns={counted:agg_name})\n",
    "    df = df.merge(gp, on=group_cols, how='left')\n",
    "    del gp\n",
    "    if show_max:\n",
    "        print( agg_name + \" max value = \", df[agg_name].max() )\n",
    "    df[agg_name] = df[agg_name].astype(agg_type)\n",
    "    gc.collect()\n",
    "    return df \n",
    "\n",
    "def do_mean(df, group_cols, counted, agg_name, agg_type='float32', show_max=False, show_agg=True ):\n",
    "    if show_agg:\n",
    "        print( \"Calculating mean of \", counted, \" by \", group_cols , '...' )\n",
    "    gp = df[group_cols+[counted]].groupby(group_cols)[counted].mean().reset_index().rename(columns={counted:agg_name})\n",
    "    df = df.merge(gp, on=group_cols, how='left')\n",
    "    del gp\n",
    "    if show_max:\n",
    "        print( agg_name + \" max value = \", df[agg_name].max() )\n",
    "    df[agg_name] = df[agg_name].astype(agg_type)\n",
    "    gc.collect()\n",
    "    return df \n",
    "\n",
    "def do_count(df, group_cols, agg_name, agg_type='uint32', show_max=False, show_agg=True ):\n",
    "    if show_agg:\n",
    "        print( \"Aggregating by \", group_cols , '...' )\n",
    "    gp = df[group_cols][group_cols].groupby(group_cols).size().rename(agg_name).to_frame().reset_index()\n",
    "    df = df.merge(gp, on=group_cols, how='left')\n",
    "    del gp\n",
    "    if show_max:\n",
    "        print( agg_name + \" max value = \", df[agg_name].max() )\n",
    "    df[agg_name] = df[agg_name].astype(agg_type)\n",
    "    gc.collect()\n",
    "    return df "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Counting unqiue  CODE_GENDER  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-NAME_INCOME_TYPE_cunique max value =  8\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-ORGANIZATION_TYPE_cunique max value =  58\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-WALLSMATERIAL_MODE_cunique max value =  8\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-NAME_INCOME_TYPE_cunique max value =  8\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-ORGANIZATION_TYPE_cunique max value =  58\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-WALLSMATERIAL_MODE_cunique max value =  8\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  CODE_GENDER  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-NAME_INCOME_TYPE_cunique max value =  8\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-ORGANIZATION_TYPE_cunique max value =  58\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-WALLSMATERIAL_MODE_cunique max value =  8\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  CODE_GENDER  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-NAME_INCOME_TYPE_cunique max value =  8\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-ORGANIZATION_TYPE_cunique max value =  58\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-WALLSMATERIAL_MODE_cunique max value =  8\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  CODE_GENDER  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-NAME_INCOME_TYPE_cunique max value =  8\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['NAME_TYPE_SUITE'] ...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NAME_TYPE_SUITE-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-ORGANIZATION_TYPE_cunique max value =  58\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-WALLSMATERIAL_MODE_cunique max value =  8\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  CODE_GENDER  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-ORGANIZATION_TYPE_cunique max value =  57\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-WALLSMATERIAL_MODE_cunique max value =  8\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  CODE_GENDER  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-NAME_INCOME_TYPE_cunique max value =  8\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-ORGANIZATION_TYPE_cunique max value =  58\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-WALLSMATERIAL_MODE_cunique max value =  8\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  CODE_GENDER  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-NAME_INCOME_TYPE_cunique max value =  8\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-ORGANIZATION_TYPE_cunique max value =  58\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-WALLSMATERIAL_MODE_cunique max value =  8\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  CODE_GENDER  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-NAME_INCOME_TYPE_cunique max value =  8\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-ORGANIZATION_TYPE_cunique max value =  58\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-WALLSMATERIAL_MODE_cunique max value =  8\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['OCCUPATION_TYPE'] ...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "OCCUPATION_TYPE-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  CODE_GENDER  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-NAME_INCOME_TYPE_cunique max value =  8\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-ORGANIZATION_TYPE_cunique max value =  58\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-WALLSMATERIAL_MODE_cunique max value =  8\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  CODE_GENDER  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-NAME_INCOME_TYPE_cunique max value =  8\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-ORGANIZATION_TYPE_cunique max value =  58\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-WALLSMATERIAL_MODE_cunique max value =  8\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  CODE_GENDER  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-NAME_INCOME_TYPE_cunique max value =  7\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-WALLSMATERIAL_MODE_cunique max value =  8\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  CODE_GENDER  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-NAME_INCOME_TYPE_cunique max value =  8\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-ORGANIZATION_TYPE_cunique max value =  58\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-WALLSMATERIAL_MODE_cunique max value =  8\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  CODE_GENDER  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['HOUSETYPE_MODE'] ...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "HOUSETYPE_MODE-NAME_INCOME_TYPE_cunique max value =  8\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-ORGANIZATION_TYPE_cunique max value =  58\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-WALLSMATERIAL_MODE_cunique max value =  8\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  CODE_GENDER  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-NAME_INCOME_TYPE_cunique max value =  8\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-ORGANIZATION_TYPE_cunique max value =  58\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  EMERGENCYSTATE_MODE  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-EMERGENCYSTATE_MODE_cunique max value =  3\n",
      "Counting unqiue  NAME_CONTRACT_TYPE  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-NAME_CONTRACT_TYPE_cunique max value =  2\n",
      "Counting unqiue  CODE_GENDER  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-CODE_GENDER_cunique max value =  3\n",
      "Counting unqiue  FLAG_OWN_CAR  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-FLAG_OWN_CAR_cunique max value =  2\n",
      "Counting unqiue  FLAG_OWN_REALTY  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-FLAG_OWN_REALTY_cunique max value =  2\n",
      "Counting unqiue  NAME_TYPE_SUITE  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-NAME_TYPE_SUITE_cunique max value =  8\n",
      "Counting unqiue  NAME_INCOME_TYPE  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-NAME_INCOME_TYPE_cunique max value =  8\n",
      "Counting unqiue  NAME_EDUCATION_TYPE  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-NAME_EDUCATION_TYPE_cunique max value =  5\n",
      "Counting unqiue  NAME_FAMILY_STATUS  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-NAME_FAMILY_STATUS_cunique max value =  6\n",
      "Counting unqiue  NAME_HOUSING_TYPE  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-NAME_HOUSING_TYPE_cunique max value =  6\n",
      "Counting unqiue  OCCUPATION_TYPE  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-OCCUPATION_TYPE_cunique max value =  19\n",
      "Counting unqiue  WEEKDAY_APPR_PROCESS_START  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-WEEKDAY_APPR_PROCESS_START_cunique max value =  7\n",
      "Counting unqiue  ORGANIZATION_TYPE  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-ORGANIZATION_TYPE_cunique max value =  58\n",
      "Counting unqiue  FONDKAPREMONT_MODE  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-FONDKAPREMONT_MODE_cunique max value =  5\n",
      "Counting unqiue  HOUSETYPE_MODE  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-HOUSETYPE_MODE_cunique max value =  4\n",
      "Counting unqiue  WALLSMATERIAL_MODE  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-WALLSMATERIAL_MODE_cunique max value =  8\n"
     ]
    }
   ],
   "source": [
    "counts_columns = []\n",
    "for f_0 in categorical_columns:\n",
    "    for f_1 in [x for x in categorical_columns if x != f_0] :\n",
    "        df = do_countuniq(df, [f_0], f_1,\n",
    "                      f_0 + '-' + f_1 + '_cunique', 'uint16', show_max=True); gc.collect()\n",
    "        counts_columns.append(f_0 + '-' + f_1 + '_cunique')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Aggregating by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE_count max value =  326537\n",
      "Aggregating by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER_count max value =  235126\n",
      "Aggregating by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR_count max value =  235235\n",
      "Aggregating by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY_count max value =  246970\n",
      "Aggregating by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE_count max value =  288253\n",
      "Aggregating by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE_count max value =  183307\n",
      "Aggregating by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE_count max value =  252379\n",
      "Aggregating by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS_count max value =  228715\n",
      "Aggregating by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE_count max value =  316513\n",
      "Aggregating by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE_count max value =  111996\n",
      "Aggregating by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START_count max value =  63652\n",
      "Aggregating by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE_count max value =  78832\n",
      "Aggregating by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE_count max value =  243092\n",
      "Aggregating by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE_count max value =  177916\n",
      "Aggregating by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE_count max value =  180234\n",
      "Aggregating by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE_count max value =  185607\n"
     ]
    }
   ],
   "source": [
    "count_columns = []\n",
    "for f_0 in categorical_columns:\n",
    "        df = do_count(df, [f_0],\n",
    "                      f_0  + '_count', 'uint16', show_max=True); gc.collect()\n",
    "        count_columns.append(f_0  + '_count')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "metadata": {},
   "outputs": [],
   "source": [
    "for f in ['AMT_ANNUITY', 'AMT_CREDIT', 'AMT_INCOME_TOTAL'] + ['EXT_SOURCE_1', 'EXT_SOURCE_2', 'EXT_SOURCE_3']:\n",
    "    new_df[f] = new_df[f].replace([np.inf, -np.inf], np.nan).fillna(new_df[f].replace([np.inf, -np.inf], np.nan).dropna().median())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Calculating mean of  AMT_ANNUITY  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-AMT_ANNUITY_mean max value =  28439.780537886978\n",
      "Calculating mean of  AMT_CREDIT  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-AMT_CREDIT_mean max value =  611841.0087876718\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-AMT_INCOME_TOTAL_mean max value =  170440.64937227633\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-EXT_SOURCE_1_mean max value =  0.5045938349042247\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-EXT_SOURCE_2_mean max value =  0.5238536075754979\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['NAME_CONTRACT_TYPE'] ...\n",
      "NAME_CONTRACT_TYPE-EXT_SOURCE_3_mean max value =  0.5141439408185883\n",
      "Calculating mean of  AMT_ANNUITY  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-AMT_ANNUITY_mean max value =  29000.096321981426\n",
      "Calculating mean of  AMT_CREDIT  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-AMT_CREDIT_mean max value =  597157.1490650155\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-AMT_INCOME_TOTAL_mean max value =  194571.8173129412\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-EXT_SOURCE_1_mean max value =  0.5245416016342868\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-EXT_SOURCE_2_mean max value =  0.5807519989440313\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['CODE_GENDER'] ...\n",
      "CODE_GENDER-EXT_SOURCE_3_mean max value =  0.5165924181042661\n",
      "Calculating mean of  AMT_ANNUITY  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-AMT_ANNUITY_mean max value =  30372.967526028755\n",
      "Calculating mean of  AMT_CREDIT  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-AMT_CREDIT_mean max value =  652786.5696826971\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-AMT_INCOME_TOTAL_mean max value =  197857.94867699555\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-EXT_SOURCE_1_mean max value =  0.5082190806279482\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-EXT_SOURCE_2_mean max value =  0.5286760232098211\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['FLAG_OWN_CAR'] ...\n",
      "FLAG_OWN_CAR-EXT_SOURCE_3_mean max value =  0.5162198834901489\n",
      "Calculating mean of  AMT_ANNUITY  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-AMT_ANNUITY_mean max value =  27461.07539003523\n",
      "Calculating mean of  AMT_CREDIT  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-AMT_CREDIT_mean max value =  608583.7058653978\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-AMT_INCOME_TOTAL_mean max value =  170749.11229934805\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-EXT_SOURCE_1_mean max value =  0.5092220106186647\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-EXT_SOURCE_2_mean max value =  0.51540622469143\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['FLAG_OWN_REALTY'] ...\n",
      "FLAG_OWN_REALTY-EXT_SOURCE_3_mean max value =  0.5183504853018818\n",
      "Calculating mean of  AMT_ANNUITY  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-AMT_ANNUITY_mean max value =  29148.45088937432\n",
      "Calculating mean of  AMT_CREDIT  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-AMT_CREDIT_mean max value =  643037.7227726635\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-AMT_INCOME_TOTAL_mean max value =  175109.69087607806\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-EXT_SOURCE_1_mean max value =  0.5262607003656236\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-EXT_SOURCE_2_mean max value =  0.5252922826170473\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['NAME_TYPE_SUITE'] ...\n",
      "NAME_TYPE_SUITE-EXT_SOURCE_3_mean max value =  0.5361407786862504\n",
      "Calculating mean of  AMT_ANNUITY  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-AMT_ANNUITY_mean max value =  67500.0\n",
      "Calculating mean of  AMT_CREDIT  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-AMT_CREDIT_mean max value =  1145454.5454545454\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-AMT_INCOME_TOTAL_mean max value =  634090.9090909091\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-EXT_SOURCE_1_mean max value =  0.6341488557633213\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-EXT_SOURCE_2_mean max value =  0.6630409655358898\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['NAME_INCOME_TYPE'] ...\n",
      "NAME_INCOME_TYPE-EXT_SOURCE_3_mean max value =  0.5516909527186679\n",
      "Calculating mean of  AMT_ANNUITY  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-AMT_ANNUITY_mean max value =  33113.568292682925\n",
      "Calculating mean of  AMT_CREDIT  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-AMT_CREDIT_mean max value =  701045.143902439\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-AMT_INCOME_TOTAL_mean max value =  236260.9756097561\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-EXT_SOURCE_1_mean max value =  0.5292943146413936\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-EXT_SOURCE_2_mean max value =  0.5710050407765975\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['NAME_EDUCATION_TYPE'] ...\n",
      "NAME_EDUCATION_TYPE-EXT_SOURCE_3_mean max value =  0.53028418406488\n",
      "Calculating mean of  AMT_ANNUITY  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-AMT_ANNUITY_mean max value =  31500.0\n",
      "Calculating mean of  AMT_CREDIT  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-AMT_CREDIT_mean max value =  631539.575576591\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-AMT_INCOME_TOTAL_mean max value =  326250.0\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-EXT_SOURCE_1_mean max value =  0.5673591913003326\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-EXT_SOURCE_2_mean max value =  0.6728929541405011\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['NAME_FAMILY_STATUS'] ...\n",
      "NAME_FAMILY_STATUS-EXT_SOURCE_3_mean max value =  0.6020666915333535\n",
      "Calculating mean of  AMT_ANNUITY  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-AMT_ANNUITY_mean max value =  28752.020833333332\n",
      "Calculating mean of  AMT_CREDIT  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-AMT_CREDIT_mean max value =  610283.5074404762\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-AMT_INCOME_TOTAL_mean max value =  189062.63541666666\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-EXT_SOURCE_1_mean max value =  0.5092913350281945\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-EXT_SOURCE_2_mean max value =  0.5336724358336338\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['NAME_HOUSING_TYPE'] ...\n",
      "NAME_HOUSING_TYPE-EXT_SOURCE_3_mean max value =  0.5168255532592988\n",
      "Calculating mean of  AMT_ANNUITY  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-AMT_ANNUITY_mean max value =  35493.331028262175\n",
      "Calculating mean of  AMT_CREDIT  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-AMT_CREDIT_mean max value =  768197.7732411305\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-AMT_INCOME_TOTAL_mean max value =  262478.3575688515\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-EXT_SOURCE_1_mean max value =  0.5583632483619353\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-EXT_SOURCE_2_mean max value =  0.5629814838441918\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['OCCUPATION_TYPE'] ...\n",
      "OCCUPATION_TYPE-EXT_SOURCE_3_mean max value =  0.5311686985591276\n",
      "Calculating mean of  AMT_ANNUITY  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-AMT_ANNUITY_mean max value =  27687.385009066413\n",
      "Calculating mean of  AMT_CREDIT  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-AMT_CREDIT_mean max value =  594724.0061929758\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-AMT_INCOME_TOTAL_mean max value =  171331.74828850623\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WEEKDAY_APPR_PROCESS_START-EXT_SOURCE_1_mean max value =  0.5060303636356729\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-EXT_SOURCE_2_mean max value =  0.5165372526798266\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['WEEKDAY_APPR_PROCESS_START'] ...\n",
      "WEEKDAY_APPR_PROCESS_START-EXT_SOURCE_3_mean max value =  0.5159211285228568\n",
      "Calculating mean of  AMT_ANNUITY  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-AMT_ANNUITY_mean max value =  33651.590782122905\n",
      "Calculating mean of  AMT_CREDIT  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-AMT_CREDIT_mean max value =  753659.748603352\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-AMT_INCOME_TOTAL_mean max value =  255180.16759776536\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-EXT_SOURCE_1_mean max value =  0.549981327597728\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-EXT_SOURCE_2_mean max value =  0.5828356105905754\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['ORGANIZATION_TYPE'] ...\n",
      "ORGANIZATION_TYPE-EXT_SOURCE_3_mean max value =  0.5516967825210805\n",
      "Calculating mean of  AMT_ANNUITY  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-AMT_ANNUITY_mean max value =  29285.94907478208\n",
      "Calculating mean of  AMT_CREDIT  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-AMT_CREDIT_mean max value =  630243.2415506958\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-AMT_INCOME_TOTAL_mean max value =  193747.5680608656\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-EXT_SOURCE_1_mean max value =  0.5223092622092567\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-EXT_SOURCE_2_mean max value =  0.5448678883533948\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['FONDKAPREMONT_MODE'] ...\n",
      "FONDKAPREMONT_MODE-EXT_SOURCE_3_mean max value =  0.5189325625711987\n",
      "Calculating mean of  AMT_ANNUITY  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-AMT_ANNUITY_mean max value =  28410.75020552403\n",
      "Calculating mean of  AMT_CREDIT  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-AMT_CREDIT_mean max value =  610606.1335934735\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-AMT_INCOME_TOTAL_mean max value =  181993.97249177904\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-EXT_SOURCE_1_mean max value =  0.5132591476541181\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-EXT_SOURCE_2_mean max value =  0.538792409676948\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['HOUSETYPE_MODE'] ...\n",
      "HOUSETYPE_MODE-EXT_SOURCE_3_mean max value =  0.5164815601707617\n",
      "Calculating mean of  AMT_ANNUITY  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-AMT_ANNUITY_mean max value =  34174.69076402321\n",
      "Calculating mean of  AMT_CREDIT  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-AMT_CREDIT_mean max value =  732226.4020793036\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-AMT_INCOME_TOTAL_mean max value =  244386.0\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-EXT_SOURCE_1_mean max value =  0.5405588384611939\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-EXT_SOURCE_2_mean max value =  0.5889211525230696\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['WALLSMATERIAL_MODE'] ...\n",
      "WALLSMATERIAL_MODE-EXT_SOURCE_3_mean max value =  0.5168274195784814\n",
      "Calculating mean of  AMT_ANNUITY  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-AMT_ANNUITY_mean max value =  28368.291155505987\n",
      "Calculating mean of  AMT_CREDIT  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-AMT_CREDIT_mean max value =  609535.2121660282\n",
      "Calculating mean of  AMT_INCOME_TOTAL  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-AMT_INCOME_TOTAL_mean max value =  181434.23034209383\n",
      "Calculating mean of  EXT_SOURCE_1  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-EXT_SOURCE_1_mean max value =  0.5130887225048275\n",
      "Calculating mean of  EXT_SOURCE_2  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-EXT_SOURCE_2_mean max value =  0.5380545214578939\n",
      "Calculating mean of  EXT_SOURCE_3  by  ['EMERGENCYSTATE_MODE'] ...\n",
      "EMERGENCYSTATE_MODE-EXT_SOURCE_3_mean max value =  0.5159656382080497\n"
     ]
    }
   ],
   "source": [
    "mean_columns = []\n",
    "for f_0 in categorical_columns:\n",
    "    for f_1 in ['AMT_ANNUITY', 'AMT_CREDIT', 'AMT_INCOME_TOTAL'] + ['EXT_SOURCE_1', 'EXT_SOURCE_2', 'EXT_SOURCE_3'] :\n",
    "        new_df = do_mean(new_df, [f_0], f_1,\n",
    "                      f_0 + '-' + f_1 + '_mean', 'uint16', show_max=True); gc.collect()\n",
    "        mean_columns.append(f_0 + '-' + f_1 + '_mean')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_features = pd.DataFrame(np.concatenate([df[count_columns][0:n_train].values, train_stacked.values, df[my_features][0:n_train].values, goran_features[0:n_train].values, suresh_august16[:n_train].values, suresh_august15[0:n_train].values], axis=1), columns=\n",
    "#                             count_columns + ['y_' + str(i) for i in range(train_stacked.shape[1])] + my_features + list(goran_features.columns) + list(suresh_august16.columns) + list(suresh_august15.columns))\n",
    "# test_features = pd.DataFrame(np.concatenate([df[count_columns][n_train:].values, test_stacked.values, df[my_features][n_train:].values, goran_features[n_train:].values, suresh_august16[n_train:].values, suresh_august15[n_train:].values], axis=1), columns=\n",
    "#                            count_columns +  ['y_' + str(i) for i in range(test_stacked.shape[1])] + my_features + list(goran_features.columns) + list(suresh_august16.columns) + list(suresh_august15.columns))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 190,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_features = np.concatenate([train_stacked.values, df[my_features][0:n_train].values, goran_features[0:n_train].values, suresh_august16[:n_train].values], axis=1)\n",
    "# test_features = np.concatenate([test_stacked.values, df[my_features][n_train:].values, goran_features[n_train:].values, suresh_august16[n_train:].values], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 191,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_features = pd.DataFrame(np.concatenate([train_stacked.values, df[my_features][0:n_train].values, goran_features[0:n_train].values, suresh_august16[:n_train].values, suresh_august15[0:n_train].values, suresh_august16_2[0:n_train].values], axis=1), columns=\n",
    "#                              ['y_' + str(i) for i in range(train_stacked.shape[1])] + my_features + list(goran_features.columns) + list(suresh_august16.columns) + list(suresh_august15.columns) + list(suresh_august16_2.columns))\n",
    "# test_features = pd.DataFrame(np.concatenate([test_stacked.values, df[my_features][n_train:].values, goran_features[n_train:].values, suresh_august16[n_train:].values, suresh_august15[n_train:].values, suresh_august16_2[n_train:].values], axis=1), columns=\n",
    "#                             ['y_' + str(i) for i in range(test_stacked.shape[1])] + my_features + list(goran_features.columns) + list(suresh_august16.columns) + list(suresh_august15.columns) + list(suresh_august16_2.columns))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_features = pd.DataFrame(np.concatenate([train_stacked.values, df[my_features][0:n_train].values, goran_features[0:n_train].values, suresh_august19[:n_train].values, suresh_august15[0:n_train].values, prevs_df[0:n_train].values, suresh_august16[0:n_train].values, suresh_august16_2[0:n_train].values], axis=1), columns=\n",
    "#                             ['y_' + str(i) for i in range(train_stacked.shape[1])] + my_features + list(goran_features.columns) + list(suresh_august19.columns) + list(suresh_august15.columns) + list(prevs_df.columns) + list(suresh_august16.columns) + list(suresh_august16_2.columns))\n",
    "# test_features = pd.DataFrame(np.concatenate([test_stacked.values, df[my_features][n_train:].values, goran_features[n_train:].values, suresh_august19[n_train:].values, suresh_august15[n_train:].values, prevs_df[n_train:].values, suresh_august16[n_train:].values, suresh_august16_2[n_train:].values], axis=1), columns=\n",
    "#                             ['y_' + str(i) for i in range(test_stacked.shape[1])] + my_features + list(goran_features.columns) + list(suresh_august19.columns) + list(suresh_august15.columns) + list(prevs_df.columns) +  list(suresh_august16.columns) + list(suresh_august16_2.columns))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 193,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_features = pd.DataFrame(np.concatenate([df[count_columns][0:n_train].values, train_stacked.values, df[my_features][0:n_train].values, suresh_august19[:n_train].values, suresh_august15[0:n_train].values, prevs_df[0:n_train].values, suresh_august16[0:n_train].values, suresh_august16_2[0:n_train].values], axis=1), columns=\n",
    "#                             count_columns + ['y_' + str(i) for i in range(train_stacked.shape[1])] + my_features  + list(suresh_august19.columns) + list(suresh_august15.columns) + list(prevs_df.columns) + list(suresh_august16.columns) + list(suresh_august16_2.columns))\n",
    "# test_features = pd.DataFrame(np.concatenate([df[count_columns][n_train:].values, test_stacked.values, df[my_features][n_train:].values, suresh_august19[n_train:].values, suresh_august15[n_train:].values, prevs_df[n_train:].values, suresh_august16[n_train:].values, suresh_august16_2[n_train:].values], axis=1), columns=\n",
    "#                             count_columns + ['y_' + str(i) for i in range(test_stacked.shape[1])] + my_features + list(suresh_august19.columns) + list(suresh_august15.columns) + list(prevs_df.columns) +  list(suresh_august16.columns) + list(suresh_august16_2.columns))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[28439, 22017, 39368, ...,     0,     0,     0],\n",
       "       [28439, 22017, 39368, ...,     0,     0,     0],\n",
       "       [16278, 61106, 35477, ...,     0,     0,     0],\n",
       "       ...,\n",
       "       [28439, 22017, 39368, ...,     0,     0,     0],\n",
       "       [28439, 22017, 39368, ...,     0,     0,     0],\n",
       "       [28439, 22017, 39368, ...,     0,     0,     0]], dtype=uint16)"
      ]
     },
     "execution_count": 212,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_df[mean_columns][0:n_train].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[28439, 22017, 39368, ...,     0,     0,     0],\n",
       "       [28439, 22017, 39368, ...,     0,     0,     0],\n",
       "       [28439, 22017, 39368, ...,     0,     0,     0],\n",
       "       ...,\n",
       "       [28439, 22017, 39368, ...,     0,     0,     0],\n",
       "       [28439, 22017, 39368, ...,     0,     0,     0],\n",
       "       [28439, 22017, 39368, ...,     0,     0,     0]], dtype=uint16)"
      ]
     },
     "execution_count": 213,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_df[mean_columns][n_train:].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 195,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gc.collect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_features = pd.DataFrame(np.concatenate([new_df[mean_columns][0:n_train].values, suresh_august16[0:n_train].values, df[count_columns][0:n_train].values , df[counts_columns][0:n_train].values,  train_stacked.values, df[my_features][0:n_train].values], axis=1), columns=\n",
    "#                             mean_columns +  list(suresh_august16.columns) + count_columns + counts_columns + ['y_' + str(i) for i in range(train_stacked.shape[1])] + my_features)\n",
    "# test_features = pd.DataFrame(np.concatenate([new_df[mean_columns][n_train:].values, suresh_august16[n_train:].values, df[count_columns][n_train:].values, df[counts_columns][n_train:].values,  test_stacked.values, df[my_features][n_train:].values], axis=1), columns=\n",
    "#                              mean_columns + list(suresh_august16.columns) + count_columns + counts_columns + ['y_' + str(i) for i in range(test_stacked.shape[1])] + my_features)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_features = pd.DataFrame(np.concatenate([suresh_august16[0:n_train].values, df[count_columns][0:n_train].values , df[counts_columns][0:n_train].values,  train_stacked.values, df[my_features][0:n_train].values], axis=1), columns=\n",
    "#                             list(suresh_august16.columns) + count_columns + counts_columns + ['y_' + str(i) for i in range(train_stacked.shape[1])] + my_features)\n",
    "# test_features = pd.DataFrame(np.concatenate([ suresh_august16[n_train:].values, df[count_columns][n_train:].values, df[counts_columns][n_train:].values,  test_stacked.values, df[my_features][n_train:].values], axis=1), columns=\n",
    "#                                list(suresh_august16.columns) + count_columns + counts_columns + ['y_' + str(i) for i in range(test_stacked.shape[1])] + my_features)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_features = pd.DataFrame(np.concatenate([df[categorical_columns][0:n_train].values, goran_features_19_8[0:n_train].values, suresh_august16[0:n_train].values, df[count_columns][0:n_train].values , df[counts_columns][0:n_train].values,  train_stacked.values, df[my_features][0:n_train].values], axis=1), columns=\n",
    "#                            categorical_columns + list(goran_features_19_8.columns) + list(suresh_august16.columns) + count_columns + counts_columns + ['y_' + str(i) for i in range(train_stacked.shape[1])] + my_features)\n",
    "# test_features = pd.DataFrame(np.concatenate([df[categorical_columns][n_train:].values, goran_features_19_8[n_train:].values, suresh_august16[n_train:].values, df[count_columns][n_train:].values, df[counts_columns][n_train:].values,  test_stacked.values, df[my_features][n_train:].values], axis=1), columns=\n",
    "#                              categorical_columns + list(goran_features_19_8.columns) +  list(suresh_august16.columns) + count_columns + counts_columns + ['y_' + str(i) for i in range(test_stacked.shape[1])] + my_features)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_features = pd.DataFrame(np.concatenate([goranm_8_20[0:n_train].values ,goran_features_19_8[0:n_train].values, suresh_august20[0:n_train].values, train_stacked.values, df[my_features][0:n_train].values, suresh_august16[:n_train].values, suresh_august15[0:n_train].values], axis=1), columns=\n",
    "#               list(goranm_8_20.columns) + list(goran_features_19_8.columns) +  list(suresh_august20.columns) + ['y_' + str(i) for i in range(train_stacked.shape[1])] + my_features + list(suresh_august16.columns) + list(suresh_august15.columns))\n",
    "# test_features = pd.DataFrame(np.concatenate([goranm_8_20[n_train:].values, goran_features_19_8[n_train:].values, suresh_august20[n_train:].values, test_stacked.values, df[my_features][n_train:].values, suresh_august16[n_train:].values, suresh_august15[n_train:].values], axis=1), columns=\n",
    "#               list(goranm_8_20.columns) + list(goran_features_19_8.columns)  + list(suresh_august20.columns) + ['y_' + str(i) for i in range(test_stacked.shape[1])] + my_features  + list(suresh_august16.columns) + list(suresh_august15.columns))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_features = pd.DataFrame(np.concatenate([goranm_8_20[0:n_train].values ,goran_features_19_8[0:n_train].values, suresh_august20[0:n_train].values, train_stacked.iloc[:, selected_features].values, df[my_features][0:n_train].values, suresh_august16[:n_train].values, suresh_august15[0:n_train].values], axis=1), columns=\n",
    "#               list(goranm_8_20.columns) + list(goran_features_19_8.columns) +  list(suresh_august20.columns) + ['y_' + str(i) for i in selected_features] + my_features + list(suresh_august16.columns) + list(suresh_august15.columns))\n",
    "# test_features = pd.DataFrame(np.concatenate([goranm_8_20[n_train:].values, goran_features_19_8[n_train:].values, suresh_august20[n_train:].values, test_stacked.iloc[:, selected_features].values, df[my_features][n_train:].values, suresh_august16[n_train:].values, suresh_august15[n_train:].values], axis=1), columns=\n",
    "#               list(goranm_8_20.columns) + list(goran_features_19_8.columns)  + list(suresh_august20.columns) + ['y_' + str(i) for i in selected_features] + my_features  + list(suresh_august16.columns) + list(suresh_august15.columns))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_features = pd.DataFrame(np.concatenate([goran_features_19_8[0:n_train].values, df[count_columns][0:n_train].values, train_stacked.values, df[my_features][0:n_train].values, goran_features[0:n_train].values, suresh_august16[:n_train].values, suresh_august15[0:n_train].values], axis=1), columns=\n",
    "#                           list(goran_features_19_8.columns) +   count_columns + ['y_' + str(i) for i in range(train_stacked.shape[1])] + my_features + list(goran_features.columns) + list(suresh_august16.columns) + list(suresh_august15.columns))\n",
    "# test_features = pd.DataFrame(np.concatenate([goran_features_19_8[n_train:].values, df[count_columns][n_train:].values, test_stacked.values, df[my_features][n_train:].values, goran_features[n_train:].values, suresh_august16[n_train:].values, suresh_august15[n_train:].values], axis=1), columns=\n",
    "#                            list(goran_features_19_8.columns) + count_columns +  ['y_' + str(i) for i in range(test_stacked.shape[1])] + my_features + list(goran_features.columns) + list(suresh_august16.columns) + list(suresh_august15.columns))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_features = pd.DataFrame(np.concatenate([df[counts_columns][0:n_train].values, df[count_columns][0:n_train].values ,new_df[mean_columns][0:n_train].values, prevs_df[0:n_train].values, suresh_20[0:n_train].values, goranm_8_20[0:n_train].values ,goran_features_19_8[0:n_train].values, suresh_august20[0:n_train].values,  df[my_features][0:n_train].values, suresh_august16[:n_train].values, suresh_august15[0:n_train].values], axis=1), columns=\n",
    "           counts_columns + count_columns + mean_columns +  list(prevs_df.columns) + list(suresh_20.columns) + list(goranm_8_20.columns) + list(goran_features_19_8.columns) +  list(suresh_august20.columns) + my_features + list(suresh_august16.columns) + list(suresh_august15.columns))\n",
    "test_features = pd.DataFrame(np.concatenate([df[counts_columns][n_train:].values, df[count_columns][n_train:].values, new_df[mean_columns][n_train:].values, prevs_df[n_train:].values, suresh_20[n_train:].values, goranm_8_20[n_train:].values, goran_features_19_8[n_train:].values, suresh_august20[n_train:].values, df[my_features][n_train:].values, suresh_august16[n_train:].values, suresh_august15[n_train:].values], axis=1), columns=\n",
    "           counts_columns + count_columns + mean_columns + list(prevs_df.columns) +   list(suresh_20.columns) + list(goranm_8_20.columns) + list(goran_features_19_8.columns)  + list(suresh_august20.columns)  + my_features  + list(suresh_august16.columns) + list(suresh_august15.columns))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>NAME_CONTRACT_TYPE-CODE_GENDER_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-FLAG_OWN_CAR_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-FLAG_OWN_REALTY_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-NAME_TYPE_SUITE_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-NAME_INCOME_TYPE_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-NAME_EDUCATION_TYPE_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-NAME_FAMILY_STATUS_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-NAME_HOUSING_TYPE_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-OCCUPATION_TYPE_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-WEEKDAY_APPR_PROCESS_START_cunique</th>\n",
       "      <th>...</th>\n",
       "      <th>AMT_INCOME_TOTAL_12_AMT_ANNUITY_2_SURESH</th>\n",
       "      <th>TOTAL_CC_LOADING_6MONTHS_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_LATE_IN_DAYS_12_MONTHS_SUM_SURESH</th>\n",
       "      <th>COUNT_SCOFR_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_OVER_AMOUNT_LAST_LOAN_MEAN_SURESH</th>\n",
       "      <th>CREDIT_PER_NON_CHILD_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_SD_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_SUM_SURESH</th>\n",
       "      <th>MEAN_PAYMENT_CC_SURESH</th>\n",
       "      <th>DAYS_DECISION_MAX_SURESH</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>284400.0</td>\n",
       "      <td>13.820275</td>\n",
       "      <td>-62.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-1740.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>111384.0</td>\n",
       "      <td>13.510284</td>\n",
       "      <td>-212.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-315.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-52902.0000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-13.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-69.078947</td>\n",
       "      <td>331632.0</td>\n",
       "      <td>7.726018</td>\n",
       "      <td>-370.0</td>\n",
       "      <td>-8.526513e-14</td>\n",
       "      <td>-222.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-32682.4875</td>\n",
       "      <td>0.264373</td>\n",
       "      <td>-12.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-837.478929</td>\n",
       "      <td>787500.0</td>\n",
       "      <td>4.914531</td>\n",
       "      <td>-140.0</td>\n",
       "      <td>7.619574e+02</td>\n",
       "      <td>-531.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>312750.0</td>\n",
       "      <td>2.667140</td>\n",
       "      <td>-147.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-111.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 422 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   NAME_CONTRACT_TYPE-CODE_GENDER_cunique  \\\n",
       "0                                     2.0   \n",
       "1                                     2.0   \n",
       "2                                     2.0   \n",
       "3                                     2.0   \n",
       "4                                     2.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-FLAG_OWN_CAR_cunique  \\\n",
       "0                                      2.0   \n",
       "1                                      2.0   \n",
       "2                                      2.0   \n",
       "3                                      2.0   \n",
       "4                                      2.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-FLAG_OWN_REALTY_cunique  \\\n",
       "0                                         2.0   \n",
       "1                                         2.0   \n",
       "2                                         2.0   \n",
       "3                                         2.0   \n",
       "4                                         2.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-NAME_TYPE_SUITE_cunique  \\\n",
       "0                                         8.0   \n",
       "1                                         8.0   \n",
       "2                                         8.0   \n",
       "3                                         8.0   \n",
       "4                                         8.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-NAME_INCOME_TYPE_cunique  \\\n",
       "0                                          7.0   \n",
       "1                                          7.0   \n",
       "2                                          7.0   \n",
       "3                                          7.0   \n",
       "4                                          7.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-NAME_EDUCATION_TYPE_cunique  \\\n",
       "0                                             5.0   \n",
       "1                                             5.0   \n",
       "2                                             5.0   \n",
       "3                                             5.0   \n",
       "4                                             5.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-NAME_FAMILY_STATUS_cunique  \\\n",
       "0                                            5.0   \n",
       "1                                            5.0   \n",
       "2                                            5.0   \n",
       "3                                            5.0   \n",
       "4                                            5.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-NAME_HOUSING_TYPE_cunique  \\\n",
       "0                                           6.0   \n",
       "1                                           6.0   \n",
       "2                                           6.0   \n",
       "3                                           6.0   \n",
       "4                                           6.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-OCCUPATION_TYPE_cunique  \\\n",
       "0                                        19.0   \n",
       "1                                        19.0   \n",
       "2                                        19.0   \n",
       "3                                        19.0   \n",
       "4                                        19.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-WEEKDAY_APPR_PROCESS_START_cunique  \\\n",
       "0                                                7.0       \n",
       "1                                                7.0       \n",
       "2                                                7.0       \n",
       "3                                                7.0       \n",
       "4                                                7.0       \n",
       "\n",
       "             ...             AMT_INCOME_TOTAL_12_AMT_ANNUITY_2_SURESH  \\\n",
       "0            ...                                                  NaN   \n",
       "1            ...                                                  NaN   \n",
       "2            ...                                          -52902.0000   \n",
       "3            ...                                          -32682.4875   \n",
       "4            ...                                                  NaN   \n",
       "\n",
       "   TOTAL_CC_LOADING_6MONTHS_SURESH  \\\n",
       "0                              NaN   \n",
       "1                              NaN   \n",
       "2                         0.000000   \n",
       "3                         0.264373   \n",
       "4                              NaN   \n",
       "\n",
       "   INSTALLMENT_PAID_LATE_IN_DAYS_12_MONTHS_SUM_SURESH  COUNT_SCOFR_SURESH  \\\n",
       "0                                                NaN                  NaN   \n",
       "1                                                NaN                  NaN   \n",
       "2                                              -13.0                  NaN   \n",
       "3                                              -12.0                  NaN   \n",
       "4                                                NaN                  NaN   \n",
       "\n",
       "   INSTALLMENT_PAID_OVER_AMOUNT_LAST_LOAN_MEAN_SURESH  \\\n",
       "0                                           0.000000    \n",
       "1                                           0.000000    \n",
       "2                                         -69.078947    \n",
       "3                                        -837.478929    \n",
       "4                                           0.000000    \n",
       "\n",
       "   CREDIT_PER_NON_CHILD_SURESH  \\\n",
       "0                     284400.0   \n",
       "1                     111384.0   \n",
       "2                     331632.0   \n",
       "3                     787500.0   \n",
       "4                     312750.0   \n",
       "\n",
       "   INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_SD_SURESH  \\\n",
       "0                                       13.820275   \n",
       "1                                       13.510284   \n",
       "2                                        7.726018   \n",
       "3                                        4.914531   \n",
       "4                                        2.667140   \n",
       "\n",
       "   INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_SUM_SURESH  MEAN_PAYMENT_CC_SURESH  \\\n",
       "0                                            -62.0                     NaN   \n",
       "1                                           -212.0                     NaN   \n",
       "2                                           -370.0           -8.526513e-14   \n",
       "3                                           -140.0            7.619574e+02   \n",
       "4                                           -147.0                     NaN   \n",
       "\n",
       "   DAYS_DECISION_MAX_SURESH  \n",
       "0                   -1740.0  \n",
       "1                    -315.0  \n",
       "2                    -222.0  \n",
       "3                    -531.0  \n",
       "4                    -111.0  \n",
       "\n",
       "[5 rows x 422 columns]"
      ]
     },
     "execution_count": 218,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_features.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 219,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3270"
      ]
     },
     "execution_count": 219,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gc.collect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "metadata": {},
   "outputs": [],
   "source": [
    "cols_to_drop = [\n",
    "    \n",
    "  'STCK_BERBAL_6_.', \n",
    "  \"FLAG_DOCUMENT_2\",\n",
    "\n",
    "  \"FLAG_DOCUMENT_7\",\n",
    "\n",
    "  \"FLAG_DOCUMENT_10\",\n",
    "\n",
    "  \"FLAG_DOCUMENT_12\",\n",
    "\n",
    "  \"FLAG_DOCUMENT_13\",\n",
    "\n",
    "  \"FLAG_DOCUMENT_14\",\n",
    "\n",
    "  \"FLAG_DOCUMENT_15\",\n",
    "\n",
    "  \"FLAG_DOCUMENT_16\",\n",
    "\n",
    "  \"FLAG_DOCUMENT_17\",\n",
    "\n",
    "  \"FLAG_DOCUMENT_18\",\n",
    "\n",
    "  \"FLAG_DOCUMENT_19\",\n",
    "\n",
    "  \"FLAG_DOCUMENT_20\",\n",
    "\n",
    "  \"FLAG_DOCUMENT_21\",\n",
    "\n",
    "  \"PREV_NAME_CONTRACT_TYPE_Consumer_loans\",\n",
    "\n",
    "  \"PREV_NAME_CONTRACT_TYPE_XNA\",\n",
    "\n",
    "  \"PB_CNT_NAME_CONTRACT_STATUS_Amortized_debt\",\n",
    "\n",
    "  \"MAX_DATA_ALL\",\n",
    "\n",
    "  \"MIN_DATA_ALL\",\n",
    "\n",
    "  \"MAX_MIN_DURATION\",\n",
    "\n",
    "  \"MAX_AMT_CREDIT_MAX_OVERDUE\",\n",
    "\n",
    "  \"CC_AMT_DRAWINGS_ATM_CURRENT_MIN\",\n",
    "\n",
    "  \"CC_AMT_DRAWINGS_OTHER_CURRENT_MAX\",\n",
    "\n",
    "  \"CC_AMT_DRAWINGS_OTHER_CURRENT_MIN\",\n",
    "\n",
    "  \"CC_CNT_DRAWINGS_ATM_CURRENT_MIN\",\n",
    "\n",
    "  \"CC_CNT_DRAWINGS_OTHER_CURRENT_MAX\",\n",
    "\n",
    "  \"CC_CNT_DRAWINGS_OTHER_CURRENT_MIN\",\n",
    "\n",
    "  \"CC_SK_DPD_DEF_MIN\",\n",
    "\n",
    "  \"CC_SK_DPD_MIN\",\n",
    "\n",
    "  \"BERB_STATUS_CREDIT_TYPE_Loan_for_working_capital_replenishment\",\n",
    "\n",
    " \"BERB_STATUS_CREDIT_TYPE_Real_estate_loan\",\n",
    "\n",
    "  \"BERB_STATUS_CREDIT_TYPE_Loan_for_the_purchase_of_equipment\",\n",
    "\n",
    "  \"BERB_COMBO_CT_CA_COMBO_CT_CA_Loan_for_working_capital_replenishmentClosed\",\n",
    "\n",
    "  \"BERB_COMBO_CT_CA_COMBO_CT_CA_Car_loanSold\",\n",
    "\n",
    "  \"BERB_COMBO_CT_CA_COMBO_CT_CA_Another_type_of_loanActive\",\n",
    "\n",
    "  \"BERB_COMBO_CT_CA_COMBO_CT_CA_Loan_for_working_capital_replenishmentSold\",\n",
    "\n",
    "  \"BERB_COMBO_CT_CA_COMBO_CT_CA_MicroloanSold\",\n",
    "\n",
    "  \"BERB_COMBO_CT_CA_COMBO_CT_CA_Another_type_of_loanSold\",\n",
    "\n",
    "  \"FLAG_EMAIL\",\n",
    "\n",
    "  \"APARTMENTS_AVG\",\n",
    "\n",
    "  \"AMT_REQ_CREDIT_BUREAU_MON\",\n",
    "\n",
    "  \"AMT_REQ_CREDIT_BUREAU_QRT\",\n",
    "\n",
    "  \"AMT_REQ_CREDIT_BUREAU_YEAR\",\n",
    "\n",
    "  \"STCK_BERBAL_6_\",\n",
    "\n",
    "  \"STCK_CC_6_x\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "metadata": {},
   "outputs": [],
   "source": [
    "feats = [f for f in cols_to_drop if f in train_features.columns]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_features.drop(labels=feats, axis=1, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_features.drop(labels=feats, axis=1, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 224,
   "metadata": {},
   "outputs": [],
   "source": [
    "cat_features = [] # [i for i in range(len(categorical_columns))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 225,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gc.collect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_stacked.to_csv('oofs/train_oofs-v0.1.0.csv', index=False)\n",
    "# test_stacked.to_csv('oofs/test_oofs-v0.1.0.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 227,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>NAME_CONTRACT_TYPE-CODE_GENDER_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-FLAG_OWN_CAR_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-FLAG_OWN_REALTY_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-NAME_TYPE_SUITE_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-NAME_INCOME_TYPE_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-NAME_EDUCATION_TYPE_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-NAME_FAMILY_STATUS_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-NAME_HOUSING_TYPE_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-OCCUPATION_TYPE_cunique</th>\n",
       "      <th>NAME_CONTRACT_TYPE-WEEKDAY_APPR_PROCESS_START_cunique</th>\n",
       "      <th>...</th>\n",
       "      <th>AMT_INCOME_TOTAL_12_AMT_ANNUITY_2_SURESH</th>\n",
       "      <th>TOTAL_CC_LOADING_6MONTHS_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_LATE_IN_DAYS_12_MONTHS_SUM_SURESH</th>\n",
       "      <th>COUNT_SCOFR_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_OVER_AMOUNT_LAST_LOAN_MEAN_SURESH</th>\n",
       "      <th>CREDIT_PER_NON_CHILD_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_SD_SURESH</th>\n",
       "      <th>INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_SUM_SURESH</th>\n",
       "      <th>MEAN_PAYMENT_CC_SURESH</th>\n",
       "      <th>DAYS_DECISION_MAX_SURESH</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>284400.0</td>\n",
       "      <td>13.820275</td>\n",
       "      <td>-62.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-1740.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>111384.0</td>\n",
       "      <td>13.510284</td>\n",
       "      <td>-212.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-315.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-52902.0000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-13.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-69.078947</td>\n",
       "      <td>331632.0</td>\n",
       "      <td>7.726018</td>\n",
       "      <td>-370.0</td>\n",
       "      <td>-8.526513e-14</td>\n",
       "      <td>-222.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-32682.4875</td>\n",
       "      <td>0.264373</td>\n",
       "      <td>-12.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-837.478929</td>\n",
       "      <td>787500.0</td>\n",
       "      <td>4.914531</td>\n",
       "      <td>-140.0</td>\n",
       "      <td>7.619574e+02</td>\n",
       "      <td>-531.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>312750.0</td>\n",
       "      <td>2.667140</td>\n",
       "      <td>-147.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-111.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 422 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   NAME_CONTRACT_TYPE-CODE_GENDER_cunique  \\\n",
       "0                                     2.0   \n",
       "1                                     2.0   \n",
       "2                                     2.0   \n",
       "3                                     2.0   \n",
       "4                                     2.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-FLAG_OWN_CAR_cunique  \\\n",
       "0                                      2.0   \n",
       "1                                      2.0   \n",
       "2                                      2.0   \n",
       "3                                      2.0   \n",
       "4                                      2.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-FLAG_OWN_REALTY_cunique  \\\n",
       "0                                         2.0   \n",
       "1                                         2.0   \n",
       "2                                         2.0   \n",
       "3                                         2.0   \n",
       "4                                         2.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-NAME_TYPE_SUITE_cunique  \\\n",
       "0                                         8.0   \n",
       "1                                         8.0   \n",
       "2                                         8.0   \n",
       "3                                         8.0   \n",
       "4                                         8.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-NAME_INCOME_TYPE_cunique  \\\n",
       "0                                          7.0   \n",
       "1                                          7.0   \n",
       "2                                          7.0   \n",
       "3                                          7.0   \n",
       "4                                          7.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-NAME_EDUCATION_TYPE_cunique  \\\n",
       "0                                             5.0   \n",
       "1                                             5.0   \n",
       "2                                             5.0   \n",
       "3                                             5.0   \n",
       "4                                             5.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-NAME_FAMILY_STATUS_cunique  \\\n",
       "0                                            5.0   \n",
       "1                                            5.0   \n",
       "2                                            5.0   \n",
       "3                                            5.0   \n",
       "4                                            5.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-NAME_HOUSING_TYPE_cunique  \\\n",
       "0                                           6.0   \n",
       "1                                           6.0   \n",
       "2                                           6.0   \n",
       "3                                           6.0   \n",
       "4                                           6.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-OCCUPATION_TYPE_cunique  \\\n",
       "0                                        19.0   \n",
       "1                                        19.0   \n",
       "2                                        19.0   \n",
       "3                                        19.0   \n",
       "4                                        19.0   \n",
       "\n",
       "   NAME_CONTRACT_TYPE-WEEKDAY_APPR_PROCESS_START_cunique  \\\n",
       "0                                                7.0       \n",
       "1                                                7.0       \n",
       "2                                                7.0       \n",
       "3                                                7.0       \n",
       "4                                                7.0       \n",
       "\n",
       "             ...             AMT_INCOME_TOTAL_12_AMT_ANNUITY_2_SURESH  \\\n",
       "0            ...                                                  NaN   \n",
       "1            ...                                                  NaN   \n",
       "2            ...                                          -52902.0000   \n",
       "3            ...                                          -32682.4875   \n",
       "4            ...                                                  NaN   \n",
       "\n",
       "   TOTAL_CC_LOADING_6MONTHS_SURESH  \\\n",
       "0                              NaN   \n",
       "1                              NaN   \n",
       "2                         0.000000   \n",
       "3                         0.264373   \n",
       "4                              NaN   \n",
       "\n",
       "   INSTALLMENT_PAID_LATE_IN_DAYS_12_MONTHS_SUM_SURESH  COUNT_SCOFR_SURESH  \\\n",
       "0                                                NaN                  NaN   \n",
       "1                                                NaN                  NaN   \n",
       "2                                              -13.0                  NaN   \n",
       "3                                              -12.0                  NaN   \n",
       "4                                                NaN                  NaN   \n",
       "\n",
       "   INSTALLMENT_PAID_OVER_AMOUNT_LAST_LOAN_MEAN_SURESH  \\\n",
       "0                                           0.000000    \n",
       "1                                           0.000000    \n",
       "2                                         -69.078947    \n",
       "3                                        -837.478929    \n",
       "4                                           0.000000    \n",
       "\n",
       "   CREDIT_PER_NON_CHILD_SURESH  \\\n",
       "0                     284400.0   \n",
       "1                     111384.0   \n",
       "2                     331632.0   \n",
       "3                     787500.0   \n",
       "4                     312750.0   \n",
       "\n",
       "   INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_SD_SURESH  \\\n",
       "0                                       13.820275   \n",
       "1                                       13.510284   \n",
       "2                                        7.726018   \n",
       "3                                        4.914531   \n",
       "4                                        2.667140   \n",
       "\n",
       "   INSTALLMENT_PAID_LATE_DAYS_LAST_LOAN_SUM_SURESH  MEAN_PAYMENT_CC_SURESH  \\\n",
       "0                                            -62.0                     NaN   \n",
       "1                                           -212.0                     NaN   \n",
       "2                                           -370.0           -8.526513e-14   \n",
       "3                                           -140.0            7.619574e+02   \n",
       "4                                           -147.0                     NaN   \n",
       "\n",
       "   DAYS_DECISION_MAX_SURESH  \n",
       "0                   -1740.0  \n",
       "1                    -315.0  \n",
       "2                    -222.0  \n",
       "3                    -531.0  \n",
       "4                    -111.0  \n",
       "\n",
       "[5 rows x 422 columns]"
      ]
     },
     "execution_count": 227,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_features.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 228,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_features['nans'] = train_features.replace([np.inf, -np.inf], np.nan).isnull().sum(axis=1)\n",
    "test_features['nans'] = test_features.replace([np.inf, -np.inf], np.nan).isnull().sum(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 246,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_file_path = \"Level_1_stack/test_catb_xxx_0.csv\"\n",
    "validation_file_path = 'Level_1_stack/validation_catb_xxx_0.csv.csv'\n",
    "num_folds = 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 247,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_features = train_features.replace([np.inf, -np.inf], np.nan).fillna(-999, inplace=False)\n",
    "# test_features = test_features.replace([np.inf, -np.inf], np.nan).fillna(-999, inplace=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Starting LightGBM. Train shape: (307511, 423), test shape: (48744, 423)\n",
      "(307511, 421)\n",
      "(246008, 421) (61503, 421) (48744, 421)\n",
      "Warning: Parameter 'use_best_model' is true, thus evaluation metric iscalculated on every iteration. 'metric_period' is ignored for evaluation metric.\n",
      "0:\tlearn: 0.2813103\ttest: 0.2859832\tbest: 0.2859832 (0)\ttotal: 91.9ms\tremaining: 3m 49s\n",
      "50:\tlearn: 0.2600347\ttest: 0.2638970\tbest: 0.2638970 (50)\ttotal: 4.76s\tremaining: 3m 48s\n",
      "100:\tlearn: 0.2582922\ttest: 0.2622716\tbest: 0.2622716 (100)\ttotal: 9.58s\tremaining: 3m 47s\n",
      "150:\tlearn: 0.2574201\ttest: 0.2616139\tbest: 0.2616139 (150)\ttotal: 14.3s\tremaining: 3m 42s\n",
      "200:\tlearn: 0.2568222\ttest: 0.2612286\tbest: 0.2612286 (200)\ttotal: 19s\tremaining: 3m 37s\n",
      "250:\tlearn: 0.2563299\ttest: 0.2609930\tbest: 0.2609930 (250)\ttotal: 23.7s\tremaining: 3m 32s\n",
      "300:\tlearn: 0.2559197\ttest: 0.2608294\tbest: 0.2608294 (300)\ttotal: 28.5s\tremaining: 3m 27s\n",
      "350:\tlearn: 0.2555578\ttest: 0.2606731\tbest: 0.2606731 (350)\ttotal: 33.2s\tremaining: 3m 23s\n",
      "400:\tlearn: 0.2552333\ttest: 0.2605597\tbest: 0.2605597 (400)\ttotal: 38s\tremaining: 3m 18s\n",
      "450:\tlearn: 0.2549128\ttest: 0.2604635\tbest: 0.2604635 (450)\ttotal: 42.8s\tremaining: 3m 14s\n",
      "500:\tlearn: 0.2546064\ttest: 0.2603882\tbest: 0.2603882 (500)\ttotal: 47.5s\tremaining: 3m 9s\n",
      "550:\tlearn: 0.2543240\ttest: 0.2603104\tbest: 0.2603104 (550)\ttotal: 52.3s\tremaining: 3m 5s\n",
      "600:\tlearn: 0.2540642\ttest: 0.2602599\tbest: 0.2602599 (600)\ttotal: 57.1s\tremaining: 3m\n",
      "650:\tlearn: 0.2537940\ttest: 0.2601982\tbest: 0.2601982 (650)\ttotal: 1m 1s\tremaining: 2m 55s\n",
      "700:\tlearn: 0.2535374\ttest: 0.2601493\tbest: 0.2601493 (700)\ttotal: 1m 6s\tremaining: 2m 51s\n",
      "750:\tlearn: 0.2533019\ttest: 0.2601072\tbest: 0.2601072 (750)\ttotal: 1m 11s\tremaining: 2m 46s\n",
      "800:\tlearn: 0.2530568\ttest: 0.2600707\tbest: 0.2600707 (800)\ttotal: 1m 16s\tremaining: 2m 41s\n",
      "850:\tlearn: 0.2528092\ttest: 0.2600220\tbest: 0.2600220 (850)\ttotal: 1m 20s\tremaining: 2m 36s\n",
      "900:\tlearn: 0.2525877\ttest: 0.2600012\tbest: 0.2600012 (900)\ttotal: 1m 25s\tremaining: 2m 32s\n",
      "950:\tlearn: 0.2523627\ttest: 0.2599795\tbest: 0.2599795 (950)\ttotal: 1m 30s\tremaining: 2m 27s\n",
      "1000:\tlearn: 0.2521391\ttest: 0.2599747\tbest: 0.2599747 (1000)\ttotal: 1m 35s\tremaining: 2m 22s\n",
      "Stopped by overfitting detector  (50 iterations wait)\n",
      "\n",
      "bestTest = 0.2599746533\n",
      "bestIteration = 1000\n",
      "\n",
      "Shrink model to first 1001 iterations.\n",
      "Fold  1 AUC : 0.787449\n",
      "(246009, 421) (61502, 421) (48744, 421)\n",
      "Warning: Parameter 'use_best_model' is true, thus evaluation metric iscalculated on every iteration. 'metric_period' is ignored for evaluation metric.\n",
      "0:\tlearn: 0.2820776\ttest: 0.2829714\tbest: 0.2829714 (0)\ttotal: 85.7ms\tremaining: 3m 34s\n",
      "50:\tlearn: 0.2605657\ttest: 0.2616257\tbest: 0.2616257 (50)\ttotal: 4.57s\tremaining: 3m 39s\n",
      "100:\tlearn: 0.2588151\ttest: 0.2601365\tbest: 0.2601365 (100)\ttotal: 9.16s\tremaining: 3m 37s\n",
      "150:\tlearn: 0.2579496\ttest: 0.2595386\tbest: 0.2595386 (150)\ttotal: 13.7s\tremaining: 3m 33s\n",
      "200:\tlearn: 0.2573461\ttest: 0.2591925\tbest: 0.2591925 (200)\ttotal: 18.3s\tremaining: 3m 28s\n",
      "250:\tlearn: 0.2568440\ttest: 0.2589652\tbest: 0.2589652 (250)\ttotal: 22.8s\tremaining: 3m 24s\n",
      "300:\tlearn: 0.2564132\ttest: 0.2587661\tbest: 0.2587661 (300)\ttotal: 27.2s\tremaining: 3m 19s\n",
      "350:\tlearn: 0.2560571\ttest: 0.2586440\tbest: 0.2586440 (350)\ttotal: 31.8s\tremaining: 3m 14s\n",
      "400:\tlearn: 0.2557451\ttest: 0.2585332\tbest: 0.2585332 (400)\ttotal: 36.4s\tremaining: 3m 10s\n",
      "450:\tlearn: 0.2554310\ttest: 0.2584536\tbest: 0.2584536 (450)\ttotal: 41s\tremaining: 3m 6s\n",
      "500:\tlearn: 0.2551421\ttest: 0.2583958\tbest: 0.2583958 (500)\ttotal: 45.5s\tremaining: 3m 1s\n",
      "550:\tlearn: 0.2548587\ttest: 0.2583172\tbest: 0.2583172 (550)\ttotal: 50.1s\tremaining: 2m 57s\n",
      "600:\tlearn: 0.2546149\ttest: 0.2582586\tbest: 0.2582586 (600)\ttotal: 54.7s\tremaining: 2m 52s\n",
      "650:\tlearn: 0.2543415\ttest: 0.2582275\tbest: 0.2582275 (650)\ttotal: 59.2s\tremaining: 2m 48s\n",
      "700:\tlearn: 0.2540995\ttest: 0.2581889\tbest: 0.2581889 (700)\ttotal: 1m 3s\tremaining: 2m 43s\n",
      "750:\tlearn: 0.2538857\ttest: 0.2581722\tbest: 0.2581722 (750)\ttotal: 1m 8s\tremaining: 2m 39s\n",
      "800:\tlearn: 0.2536638\ttest: 0.2581435\tbest: 0.2581435 (800)\ttotal: 1m 12s\tremaining: 2m 34s\n",
      "850:\tlearn: 0.2534281\ttest: 0.2581086\tbest: 0.2581086 (850)\ttotal: 1m 17s\tremaining: 2m 30s\n",
      "900:\tlearn: 0.2531998\ttest: 0.2580936\tbest: 0.2580936 (900)\ttotal: 1m 22s\tremaining: 2m 25s\n",
      "950:\tlearn: 0.2529963\ttest: 0.2580630\tbest: 0.2580630 (950)\ttotal: 1m 26s\tremaining: 2m 20s\n",
      "1000:\tlearn: 0.2527993\ttest: 0.2580310\tbest: 0.2580310 (1000)\ttotal: 1m 31s\tremaining: 2m 16s\n",
      "1050:\tlearn: 0.2525840\ttest: 0.2579987\tbest: 0.2579987 (1050)\ttotal: 1m 35s\tremaining: 2m 11s\n",
      "1100:\tlearn: 0.2523778\ttest: 0.2579869\tbest: 0.2579869 (1100)\ttotal: 1m 40s\tremaining: 2m 7s\n",
      "1150:\tlearn: 0.2521834\ttest: 0.2579727\tbest: 0.2579727 (1150)\ttotal: 1m 44s\tremaining: 2m 2s\n",
      "1200:\tlearn: 0.2519831\ttest: 0.2579696\tbest: 0.2579696 (1200)\ttotal: 1m 49s\tremaining: 1m 58s\n",
      "Stopped by overfitting detector  (50 iterations wait)\n",
      "\n",
      "bestTest = 0.2579696417\n",
      "bestIteration = 1200\n",
      "\n",
      "Shrink model to first 1201 iterations.\n",
      "Fold  2 AUC : 0.788383\n",
      "(246009, 421) (61502, 421) (48744, 421)\n",
      "Warning: Parameter 'use_best_model' is true, thus evaluation metric iscalculated on every iteration. 'metric_period' is ignored for evaluation metric.\n",
      "0:\tlearn: 0.2828369\ttest: 0.2797438\tbest: 0.2797438 (0)\ttotal: 91.4ms\tremaining: 3m 48s\n",
      "50:\tlearn: 0.2610589\ttest: 0.2592571\tbest: 0.2592571 (50)\ttotal: 4.82s\tremaining: 3m 51s\n",
      "100:\tlearn: 0.2592691\ttest: 0.2580388\tbest: 0.2580388 (100)\ttotal: 9.64s\tremaining: 3m 49s\n",
      "150:\tlearn: 0.2584348\ttest: 0.2575508\tbest: 0.2575508 (150)\ttotal: 14.4s\tremaining: 3m 44s\n",
      "200:\tlearn: 0.2578273\ttest: 0.2572210\tbest: 0.2572210 (200)\ttotal: 19.1s\tremaining: 3m 38s\n",
      "250:\tlearn: 0.2573360\ttest: 0.2570073\tbest: 0.2570073 (250)\ttotal: 23.9s\tremaining: 3m 34s\n",
      "300:\tlearn: 0.2569029\ttest: 0.2568631\tbest: 0.2568631 (300)\ttotal: 28.6s\tremaining: 3m 29s\n",
      "350:\tlearn: 0.2565004\ttest: 0.2567196\tbest: 0.2567196 (350)\ttotal: 33.4s\tremaining: 3m 24s\n",
      "400:\tlearn: 0.2561677\ttest: 0.2566402\tbest: 0.2566402 (400)\ttotal: 38.2s\tremaining: 3m 19s\n",
      "450:\tlearn: 0.2558729\ttest: 0.2565718\tbest: 0.2565718 (450)\ttotal: 43s\tremaining: 3m 15s\n",
      "500:\tlearn: 0.2555797\ttest: 0.2565110\tbest: 0.2565110 (500)\ttotal: 47.7s\tremaining: 3m 10s\n",
      "550:\tlearn: 0.2553069\ttest: 0.2564554\tbest: 0.2564554 (550)\ttotal: 52.6s\tremaining: 3m 5s\n",
      "600:\tlearn: 0.2550320\ttest: 0.2564197\tbest: 0.2564197 (600)\ttotal: 57.4s\tremaining: 3m 1s\n",
      "650:\tlearn: 0.2547821\ttest: 0.2563751\tbest: 0.2563751 (650)\ttotal: 1m 2s\tremaining: 2m 56s\n",
      "700:\tlearn: 0.2545358\ttest: 0.2563253\tbest: 0.2563253 (700)\ttotal: 1m 6s\tremaining: 2m 51s\n",
      "750:\tlearn: 0.2542960\ttest: 0.2562744\tbest: 0.2562744 (750)\ttotal: 1m 11s\tremaining: 2m 46s\n",
      "800:\tlearn: 0.2540669\ttest: 0.2562341\tbest: 0.2562341 (800)\ttotal: 1m 16s\tremaining: 2m 42s\n",
      "850:\tlearn: 0.2538423\ttest: 0.2562182\tbest: 0.2562182 (850)\ttotal: 1m 21s\tremaining: 2m 37s\n",
      "900:\tlearn: 0.2536217\ttest: 0.2561972\tbest: 0.2561972 (900)\ttotal: 1m 26s\tremaining: 2m 32s\n",
      "950:\tlearn: 0.2534215\ttest: 0.2561639\tbest: 0.2561639 (950)\ttotal: 1m 30s\tremaining: 2m 28s\n",
      "1000:\tlearn: 0.2531914\ttest: 0.2561424\tbest: 0.2561424 (1000)\ttotal: 1m 35s\tremaining: 2m 23s\n",
      "1050:\tlearn: 0.2529902\ttest: 0.2561243\tbest: 0.2561243 (1050)\ttotal: 1m 40s\tremaining: 2m 18s\n",
      "1100:\tlearn: 0.2527805\ttest: 0.2561065\tbest: 0.2561065 (1100)\ttotal: 1m 45s\tremaining: 2m 13s\n",
      "1150:\tlearn: 0.2525628\ttest: 0.2560954\tbest: 0.2560954 (1150)\ttotal: 1m 49s\tremaining: 2m 8s\n",
      "1200:\tlearn: 0.2523590\ttest: 0.2560769\tbest: 0.2560769 (1200)\ttotal: 1m 54s\tremaining: 2m 4s\n",
      "1250:\tlearn: 0.2521731\ttest: 0.2560593\tbest: 0.2560593 (1250)\ttotal: 1m 59s\tremaining: 1m 59s\n",
      "1300:\tlearn: 0.2519732\ttest: 0.2560372\tbest: 0.2560372 (1300)\ttotal: 2m 4s\tremaining: 1m 54s\n",
      "1350:\tlearn: 0.2517694\ttest: 0.2560219\tbest: 0.2560219 (1350)\ttotal: 2m 9s\tremaining: 1m 49s\n",
      "1400:\tlearn: 0.2515749\ttest: 0.2560128\tbest: 0.2560128 (1400)\ttotal: 2m 14s\tremaining: 1m 45s\n",
      "1450:\tlearn: 0.2513860\ttest: 0.2559990\tbest: 0.2559990 (1450)\ttotal: 2m 18s\tremaining: 1m 40s\n",
      "1500:\tlearn: 0.2511968\ttest: 0.2559767\tbest: 0.2559767 (1500)\ttotal: 2m 23s\tremaining: 1m 35s\n",
      "1550:\tlearn: 0.2509983\ttest: 0.2559690\tbest: 0.2559690 (1550)\ttotal: 2m 28s\tremaining: 1m 30s\n",
      "Stopped by overfitting detector  (50 iterations wait)\n",
      "\n",
      "bestTest = 0.2559690303\n",
      "bestIteration = 1550\n",
      "\n",
      "Shrink model to first 1551 iterations.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fold  3 AUC : 0.778853\n",
      "(246009, 421) (61502, 421) (48744, 421)\n",
      "Warning: Parameter 'use_best_model' is true, thus evaluation metric iscalculated on every iteration. 'metric_period' is ignored for evaluation metric.\n",
      "0:\tlearn: 0.2823437\ttest: 0.2821966\tbest: 0.2821966 (0)\ttotal: 90.3ms\tremaining: 3m 45s\n",
      "50:\tlearn: 0.2606358\ttest: 0.2611654\tbest: 0.2611654 (50)\ttotal: 4.82s\tremaining: 3m 51s\n",
      "100:\tlearn: 0.2588962\ttest: 0.2597523\tbest: 0.2597523 (100)\ttotal: 9.62s\tremaining: 3m 48s\n",
      "150:\tlearn: 0.2580271\ttest: 0.2591569\tbest: 0.2591569 (150)\ttotal: 14.4s\tremaining: 3m 44s\n",
      "200:\tlearn: 0.2573996\ttest: 0.2587936\tbest: 0.2587936 (200)\ttotal: 19.1s\tremaining: 3m 38s\n",
      "250:\tlearn: 0.2569301\ttest: 0.2585362\tbest: 0.2585362 (250)\ttotal: 23.9s\tremaining: 3m 34s\n",
      "300:\tlearn: 0.2565027\ttest: 0.2583558\tbest: 0.2583558 (300)\ttotal: 28.7s\tremaining: 3m 29s\n",
      "350:\tlearn: 0.2561332\ttest: 0.2582071\tbest: 0.2582071 (350)\ttotal: 33.4s\tremaining: 3m 24s\n",
      "400:\tlearn: 0.2558082\ttest: 0.2580959\tbest: 0.2580959 (400)\ttotal: 38.1s\tremaining: 3m 19s\n",
      "450:\tlearn: 0.2555063\ttest: 0.2580028\tbest: 0.2580028 (450)\ttotal: 42.9s\tremaining: 3m 15s\n",
      "500:\tlearn: 0.2552172\ttest: 0.2579310\tbest: 0.2579310 (500)\ttotal: 47.7s\tremaining: 3m 10s\n",
      "550:\tlearn: 0.2549400\ttest: 0.2578509\tbest: 0.2578509 (550)\ttotal: 52.5s\tremaining: 3m 5s\n",
      "600:\tlearn: 0.2546805\ttest: 0.2578028\tbest: 0.2578028 (600)\ttotal: 57.3s\tremaining: 3m 1s\n",
      "650:\tlearn: 0.2544205\ttest: 0.2577406\tbest: 0.2577406 (650)\ttotal: 1m 2s\tremaining: 2m 56s\n",
      "700:\tlearn: 0.2541766\ttest: 0.2577148\tbest: 0.2577148 (700)\ttotal: 1m 6s\tremaining: 2m 51s\n",
      "750:\tlearn: 0.2539318\ttest: 0.2576803\tbest: 0.2576803 (750)\ttotal: 1m 11s\tremaining: 2m 46s\n",
      "800:\tlearn: 0.2537209\ttest: 0.2576486\tbest: 0.2576486 (800)\ttotal: 1m 16s\tremaining: 2m 41s\n",
      "850:\tlearn: 0.2534773\ttest: 0.2576176\tbest: 0.2576176 (850)\ttotal: 1m 21s\tremaining: 2m 37s\n",
      "900:\tlearn: 0.2532326\ttest: 0.2575973\tbest: 0.2575973 (900)\ttotal: 1m 25s\tremaining: 2m 32s\n",
      "950:\tlearn: 0.2530206\ttest: 0.2575634\tbest: 0.2575634 (950)\ttotal: 1m 30s\tremaining: 2m 27s\n",
      "1000:\tlearn: 0.2528177\ttest: 0.2575429\tbest: 0.2575429 (1000)\ttotal: 1m 35s\tremaining: 2m 22s\n",
      "1050:\tlearn: 0.2526292\ttest: 0.2575304\tbest: 0.2575304 (1050)\ttotal: 1m 40s\tremaining: 2m 18s\n",
      "1100:\tlearn: 0.2524285\ttest: 0.2575033\tbest: 0.2575033 (1100)\ttotal: 1m 45s\tremaining: 2m 13s\n",
      "1150:\tlearn: 0.2522430\ttest: 0.2574907\tbest: 0.2574907 (1150)\ttotal: 1m 49s\tremaining: 2m 8s\n",
      "1200:\tlearn: 0.2520476\ttest: 0.2574673\tbest: 0.2574673 (1200)\ttotal: 1m 54s\tremaining: 2m 3s\n",
      "1250:\tlearn: 0.2518424\ttest: 0.2574590\tbest: 0.2574590 (1250)\ttotal: 1m 59s\tremaining: 1m 59s\n",
      "1300:\tlearn: 0.2516323\ttest: 0.2574323\tbest: 0.2574323 (1300)\ttotal: 2m 4s\tremaining: 1m 54s\n",
      "1350:\tlearn: 0.2514178\ttest: 0.2574266\tbest: 0.2574266 (1350)\ttotal: 2m 8s\tremaining: 1m 49s\n",
      "1400:\tlearn: 0.2512062\ttest: 0.2574231\tbest: 0.2574231 (1400)\ttotal: 2m 13s\tremaining: 1m 44s\n",
      "1450:\tlearn: 0.2510220\ttest: 0.2574070\tbest: 0.2574070 (1450)\ttotal: 2m 18s\tremaining: 1m 40s\n",
      "1500:\tlearn: 0.2508337\ttest: 0.2573981\tbest: 0.2573981 (1500)\ttotal: 2m 23s\tremaining: 1m 35s\n",
      "1550:\tlearn: 0.2506366\ttest: 0.2573821\tbest: 0.2573821 (1550)\ttotal: 2m 28s\tremaining: 1m 30s\n",
      "1600:\tlearn: 0.2504633\ttest: 0.2573833\tbest: 0.2573821 (1550)\ttotal: 2m 32s\tremaining: 1m 25s\n",
      "1650:\tlearn: 0.2502808\ttest: 0.2573862\tbest: 0.2573821 (1550)\ttotal: 2m 37s\tremaining: 1m 21s\n",
      "Stopped by overfitting detector  (50 iterations wait)\n",
      "\n",
      "bestTest = 0.2573820828\n",
      "bestIteration = 1550\n",
      "\n",
      "Shrink model to first 1551 iterations.\n",
      "Fold  4 AUC : 0.784436\n",
      "(246009, 421) (61502, 421) (48744, 421)\n",
      "Warning: Parameter 'use_best_model' is true, thus evaluation metric iscalculated on every iteration. 'metric_period' is ignored for evaluation metric.\n",
      "0:\tlearn: 0.2827228\ttest: 0.2804224\tbest: 0.2804224 (0)\ttotal: 91ms\tremaining: 3m 47s\n",
      "50:\tlearn: 0.2610857\ttest: 0.2594735\tbest: 0.2594735 (50)\ttotal: 4.81s\tremaining: 3m 50s\n",
      "100:\tlearn: 0.2593327\ttest: 0.2579466\tbest: 0.2579466 (100)\ttotal: 9.6s\tremaining: 3m 48s\n",
      "150:\tlearn: 0.2584764\ttest: 0.2573309\tbest: 0.2573309 (150)\ttotal: 14.4s\tremaining: 3m 43s\n"
     ]
    }
   ],
   "source": [
    "gc.collect()\n",
    "encoding = 'ohe'\n",
    "\n",
    "train_df = train_features\n",
    "test_df = test_features\n",
    "\n",
    "print(\"Starting LightGBM. Train shape: {}, test shape: {}\".format(train_df.shape, test_df.shape))\n",
    "gc.collect()\n",
    "# Cross validation model\n",
    "folds = KFold(n_splits=num_folds, shuffle=True, random_state=1001)\n",
    "# Create arrays and dataframes to store results\n",
    "oof_preds = np.zeros(train_df.shape[0])\n",
    "sub_preds = np.zeros(test_df.shape[0])\n",
    "feature_importance_df = pd.DataFrame()\n",
    "feats = [f for f in train_df.columns if f not in ['TARGET','SK_ID_CURR','SK_ID_BUREAU','SK_ID_PREV','index']]\n",
    "\n",
    "#feats = [col for col in feats_0 if df[col].dtype == 'object']\n",
    "\n",
    "\n",
    "print(train_df[feats].shape)\n",
    "for n_fold, (train_idx, valid_idx) in enumerate(folds.split(train_df[feats], train['TARGET'])):\n",
    "        \n",
    "      \n",
    "    \n",
    "        if encoding == 'ohe':\n",
    "            x_train = train_df[feats].iloc[train_idx]\n",
    "            #cat_features = [i for i, col in enumerate(x_train.columns) if col in categorical_cols]\n",
    "            x_train = x_train.replace([np.inf, -np.inf], np.nan).fillna(-999).values\n",
    "            x_valid = train_df[feats].iloc[valid_idx].replace([np.inf, -np.inf], np.nan).fillna(-999).values\n",
    "            x_test = test_df[feats].replace([np.inf, -np.inf], np.nan).fillna(-999).values\n",
    "            print(x_train.shape, x_valid.shape, x_test.shape)\n",
    "            \n",
    "            gc.collect()\n",
    "            \n",
    "        clf = CatBoostRegressor(learning_rate=0.05, iterations=2500, verbose=True, rsm=0.25,\n",
    "                              use_best_model=True, l2_leaf_reg=40, allow_writing_files=False, metric_period=50,\n",
    "                              random_seed=666, depth=6, loss_function='RMSE', od_wait=50, od_type='Iter')\n",
    "\n",
    "        clf.fit(x_train, train['TARGET'].iloc[train_idx].values, eval_set=(x_valid, train['TARGET'].iloc[valid_idx].values)\n",
    "                    , cat_features=[], use_best_model=True, verbose=True)\n",
    "\n",
    "        oof_preds[valid_idx] = clf.predict(x_valid)\n",
    "        sub_preds += clf.predict(x_test) / folds.n_splits\n",
    "\n",
    "        print('Fold %2d AUC : %.6f' % (n_fold + 1, roc_auc_score(train['TARGET'].iloc[valid_idx].values, oof_preds[valid_idx])))\n",
    "        del clf\n",
    "        gc.collect()\n",
    "    \n",
    "        \n",
    "        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sub_df = test[['SK_ID_CURR']].copy()\n",
    "sub_df['TARGET'] = sub_preds\n",
    "sub_df[['SK_ID_CURR', 'TARGET']].to_csv(test_file_path, index= False)\n",
    "\n",
    "\n",
    "val_df = train[['SK_ID_CURR', 'TARGET']].copy()\n",
    "val_df['TARGET'] = oof_preds\n",
    "val_df[['SK_ID_CURR', 'TARGET']].to_csv(validation_file_path, index= False)        \n",
    "\n",
    "gc.collect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
